怎样查询SQL数据库中某一个表中的某个列的一个数值的所有行数据?

怎样查询SQL数据库中某一个表中的某个列的一个数值的所有行数据?,第1张

select * from accuont where VIP = 1 \x0d\x0a//上面的1 是在你表中的类型为数字类型的时候\x0d\x0aselect * from accuont where VIP='1'\x0d\x0a//上面的1 是在你表中的类型为非数字类型的时候\x0d\x0a第一个:查询下拉框的选项\x0d\x0aselect a.Name,a.ID form TBMenu a where a.IsUsed=1\x0d\x0a查询Name和ID: Name为显示文字,ID用于在选择这个选项后根据ID值进行下一步的查询\x0d\x0a在你后台执行SQL的时候返回一个dateset 然后用combobox的datasuoce绑定,怎么绑需要自己找例子,很好的学习过程。\x0d\x0a第二个:根据选择的菜单查询需要的信息\x0d\x0aselect * from Infomations a where a.MenuID=ID(选择下拉框选项对应的ID值)\x0d\x0a在下拉框中选择“主食”,点击查询按钮,肯定是要查询和主食相关的数据,那就通过主食对应的ID(也就是下拉框绑定的时候查询的ID)去数据库对应的关联表中查询对应的信息。\x0d\x0a这个地方你没有描述清楚你想实现的效果所以,根据你在上面补充的内容推测出的这些东西。

select d.name as 表名,COUNT (*)as 记录 from syscolumns a inner join sysobjects d on a.id = d.id and d.xtype = 'U'

group by d.name

这是sqlserver 实现的,不知道符不符合。不过刚刚验证了一下,不是很对,估计是主键的原因,修改好了再看看

以上语句只能测试出部分,这个存储过程可以实现全部,sqlserver直接执行即可:

create table #temp(Recordcount int ,tableName varchar(30))

declare @tablename varchar(30)

declare @sql varchar(100)

declare @str varchar(30)

declare tablecursor cursor for

select name from sysobjects where xtype='u'

open tablecursor

fetch next from tablecursor into @tablename

while @@fetch_status=0

begin

set @str=@tablename

set @sql='insert into #temp(recordcount,tablename) select count(*),'+''''+@tablename+''''+' from '+@tablename

exec(@sql)

fetch next from tablecursor into @tablename

end

close tablecursor

deallocate tablecursor

select * from #temp drop table #temp

可以实现

use information_schema

select table_name,table_rows from tables

where TABLE_SCHEMA = '数据库名'

order by table_rows desc

查询出来的是每张表的行数


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9883904.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存