日期:2014-05-18 浏览次数:20766 次
/********查找...有數據的表********/
if object_id('TEMPDB..#temp') is not null drop table #temp
if object_id('_temp','U') is not null drop table _temp
go
select 'insert into _temp/*(tb_name,row_count)*/ select '''+name+''',count(*) as a from '+name as name
into #temp
from sysobjects where xtype = 'U' order by name
create table _temp (tb_name varchar(50),row_count decimal(10,0))
declare @sql nchar(200)
declare cur_1 cursor for select name from #temp
open cur_1 fetch from cur_1 into @sql
while @@fetch_status=0
begin
exec sp_executesql @sql
fetch from cur_1 into @sql
end
close cur_1 deallocate cur_1
if object_id('TEMPDB..#temp') is not null drop table #temp
--if object_id('_temp','U') is not null drop table _temp
select * from _temp
go