
sqlserver数据库sql语句搜索空表和非空表
查询数据库空表有哪些:
use 库名 go declare @tablename nvarchar(100) declare @sql nvarchar(2000) declare @count int declare @a int declare cur_c cursor for select name from sysobjects where xtype='U' and status>=0 open cur_c fetch next from cur_c into @tablename while @@fetch_status = 0 begin set @sql='select @a=count(*) from '+@tablename+'' exec sp_executesql @sql,N'@a int output',@count output if @count=0 print @tablename fetch next from cur_c into @tablename end close cur_c deallocate cur_c查询数据库非空表有哪些
--这个根据存储区来判断 select B.name from sys.partitions A inner join sys.objects B on A.object_id=B.object_id where B.type='U' and A.rows>0 --这个根据索引表来判断 select B.name from sysindexes A inner join sys.objects B on A.id=B.object_id where B.type='U' And A.rows >0👁️ 阅读量:0
© 版权声明:本文《sqlserver数据库sql语句搜索空表和非空表》内容均为本站精心整理或网友自愿分享,如需转载请注明原文出处:https://www.zastudy.cn/wen/1686656486a318301.html。