--创建临时表
create table #temp(Recordcount int ,tableName varchar(30))
--用游标将查询的记录数,插入临时表
declare @tablename varchar(30)declare @sql varchar(100)declare @str varchar(30)declare tablecursor cursor forselect name from sysobjects where xtype='u'open tablecursorfetch next from tablecursor into @tablenamewhile @@fetch_status=0beginset @str=@tablenameset @sql='insert into #temp(recordcount,tablename) select count(*),'+''''+@tablename+''''+' from exec(@sql)fetch next from tablecursor into @tablenameendclose tablecursordeallocate tablecursor
--查询临时表,即可看见一个数据库的每个表的记录数
select * from #temp
--最后删除临时表
drop table #temp