发表于: 2004.12.09 22:42
分类: dbms
出处: http://kyle.itpub.net/post/1626/9272
---------------------------------------------------------------
create table #temp(name varchar(50),count int)
declare @tablename varchar(50),@sql varchar(500)
declare gettablenum_cur cursor for select name from sysobjects where xtype='u'
open gettablenum_cur
fetch gettablenum_cur into @tablename
while @@fetch_status=0
begin
select @sql='insert #temp(name,count) '+'select '+''''+@tablename+''''+','+'count(1) from '+@tablename
exec(@sql)
fetch gettablenum_cur into @tablename
end
select * from #temp order by name
close gettablenum_cur
deallocate gettablenum_cur
drop table #temp











