Technical Article

Count and display number of rows in all tables

,

This script can be used to display the number of rows of all the tables in a database.

declare @tablename varchar(255)
declare curTables cursor for
select name from sysobjects
where type='U'
order by  name
declare @statement varchar(1000)

create table #temp 
 (tablename varchar(255),[rows] int)

open  curTables

fetch next from curTables into @tablename
while @@fetch_status=0
begin

select @statement='insert into #temp select '''+@tablename+''',count(*) from '+@tablename
print @statement
exec (@statement)

fetch next from curTables into @tablename

end

close  curTables
deallocate curTables

select * from #temp

drop table #temp

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating