
正文
sqlserver查空,sql 空
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
如何查询SqlServer中所有表的数据行数,并且显示所有空表非空表
1、以数据库text为例:
USE text
go
SELECT ?A.NAME,MaxRows = MAX(B.rows)
FROM sys.tables A
INNER JOIN sys.partitions B?ON A.object_id = B.object_id
GROUP BY A.name
ORDER BY MAX(B.rows) DESC?- -按数据行数的降序进行排序显示
2、显示所有空表
USE text
go
SELECT ?A.NAME,MaxRows = MAX(B.rows)
FROM sys.tables A
INNER JOIN sys.partitions B?ON A.object_id = B.object_id
GROUP BY A.name
HAVING MAX(B.rows) = 0
3、显示所有非空表
USE text
go
SELECT ?A.NAME,MaxRows = MAX(B.rows)
FROM sys.tables A
INNER JOIN sys.partitions B?ON A.object_id = B.object_id
GROUP BY A.name
HAVING MAX(B.rows) 0
相关问答
Q1: SqlServer存储过程中用where case when无法查出有字段为空的全部数据
// 尝试下面这个:
if len(@tel)=0 and len(@address)=0
begin
select * from T
end
else
begin
if len(@tel)=0
begin
select * from T where address like '%'+@address+'%'
end
if len(@address)=0
begin
select * from T where tel like '%'+@tel+'%'
end
if len(@tel)0 and len(@address)0
begin
select * from T where tel like '%'+@tel+'%' and address like '%'+@address+'%'
end
end
Q2: sql Server 查询出表中一个字段为空的数量
因为count统计语句是统计不出null的,所以用
select count(address) from test where address is null
得出的结果一定是0,知道了原因,相应的解决办法就有了,可以统计不为空的列,假如name列不可以为空,每一行都有数据,那么可以用下面的语句来查询
select count(name) from test where address is null and name is not null
Q3: SQLServer 有SQL语句 怎么判断一列(很多可以为空的字段)值中有空值或者为NUll
在sql中
空值有NULL 和''的形式
当是NULL的时候用 IS NULL判断
当是''的时候用 =''判断
比如
select * from table where enddate IS NULL;
select * from table where str='';
Q4: sqlserver查询某列可能为空也可能有值的所有的项
假设学生信息表为student,班级信息表为classtable
select s.id as 编号,s.name as 姓名,s.age as 年龄,c.classname as 班级名 from student s left join classtable c on s.classid = c.id
修改上面句子的student和classtable为你的实际表名
Q5: ms sqlserver 查询字符串 空格
我也查了一下,后面纯空格是可以的,只匹配到admin,后面如果是纯空格,不管几个都是和直接写admin是一样的。
如果你想匹配‘admin ’(后面带空格的),建议在name字段后面加一个‘_’来查询,例如:
select * from where name+'_'='admin _'








