.

just some code – example to do rowcount

declare x cursor local for
select name from sys.tables  where name != 'sysdiagrams' order by name;

declare @Tname nvarchar(50)
declare @SQL nvarchar(4000)
select @SQL = N''
declare @xFETCH_STATUS int
declare @statement nvarchar(250)

open x
FETCH NEXT FROM x
into @Tname
select @xFETCH_STATUS  =  @@FETCH_STATUS
while @xFETCH_STATUS = 0
begin
    select @SQL = @SQL + N' select '
    select @SQL = @SQL + N' '''+@Tname+''' as Tname, count(*) as Count from ' +  @Tname
    EXEC dbo.sp_executesql @statement
    FETCH NEXT FROM x into @Tname
    select @xFETCH_STATUS  =  @@FETCH_STATUS
if @xFETCH_STATUS = 0
select @SQL = @SQL + ' union '
end
close x
deallocate x
--print @SQL   -- if you want to see the code
exec dbo.sp_executesql @SQL
go

What's your thoughts on this?

*

Protected by WP Anti Spam