Pages

Saturday, June 1, 2013

How to list all table row counts in a database?

Execute the following Microsoft SQL Server T-SQL script to demonstrate how to obtain row counts for all tables in a database using an undocumented system procedure.

use AdventureWorks2008;
go
create table #RowCount (TableName sysname, NoOfRows int)
exec sp_MSforeachtable
'insert into #RowCount select ''?'', count(*) from ?'
select * from #RowCount
order by NoOfRows desc
drop table #RowCount
go

No comments:

Post a Comment