Friday, March 23, 2012

Script to do count(*) on all tables

Is there a script to do a count(*) on all tables in a given db?
Thanks.
ArcherHere's a script that may help
select table_name
into #temp
from information_schema.tables
where table_type = 'base table'
order by table_name
declare @.table varchar(50)
while exists (select 'x' from #temp)
begin
select top 1 @.table = table_name
from #temp
print 'Processing table ' + upper(@.table)
exec ('select * from ' + @.table)
delete from #temp where table_name = @.table
end
"bagman3rd" <bagman3rd@.discussions.microsoft.com> wrote in message
news:8FE75DF5-C691-4238-A2C8-19736361E583@.microsoft.com...
> Is there a script to do a count(*) on all tables in a given db?
> Thanks.
> Archer|||Do a google on the undocumented SPs: sp_MSforeachdb and sp_MSforeachtable
"bagman3rd" <bagman3rd@.discussions.microsoft.com> wrote in message
news:8FE75DF5-C691-4238-A2C8-19736361E583@.microsoft.com...
> Is there a script to do a count(*) on all tables in a given db?
> Thanks.
> Archer|||See if this helps: http://tinyurl.com/brv3g
Anithsql

No comments:

Post a Comment