- 得到数据库中各表格的数据量大于0的表格
SQL
1 DECLARE @tbname VARCHAR(250)
2 DECLARE #tb CURSOR FOR SELECT name FROM sysobjects WHERE OBJECTPROPERTY(id,'IsUserTable')=1
3 OPEN #tb
4 FETCH NEXT FROM #tb INTO @tbname
5 WHILE @@fetch_status = 0
6 BEGIN
7 EXEC ('
8 declare @count int
9 select @count = count(*) from '+@tbname+'
10 if @count>0
11 print Str(@count,5)+'' ''+'''+@tbname+'''
12 ')
13 FETCH NEXT FROM #tb INTO @tbname
14 END
15 CLOSE #tb
16 DEALLOCATE #tb
2 DECLARE #tb CURSOR FOR SELECT name FROM sysobjects WHERE OBJECTPROPERTY(id,'IsUserTable')=1
3 OPEN #tb
4 FETCH NEXT FROM #tb INTO @tbname
5 WHILE @@fetch_status = 0
6 BEGIN
7 EXEC ('
8 declare @count int
9 select @count = count(*) from '+@tbname+'
10 if @count>0
11 print Str(@count,5)+'' ''+'''+@tbname+'''
12 ')
13 FETCH NEXT FROM #tb INTO @tbname
14 END
15 CLOSE #tb
16 DEALLOCATE #tb