Display Row count for all tables

>>Script Language and Platform: SQL Server
This script returns the number of rows in each table for a database.

Author: Shyam SKJ



create procedure [dbo].[DisplayRowCount] as
declare @tabcnt int
declare @printline char (60)
select @tabcnt = count (*) from sysobjects where type = ‘U’

If @tabcnt != 0
BEGIN
select “TABLE NAME”= convert (varchar (50), o.name), ROWS=i.rows
from sysobjects o, sysindexes i
where o.type = ‘U’
and o.id = i.id
and i.indid in (0,1)
order by o.name
END

select @printline = “(” + convert (varchar(10), @tabcnt) +
” tables in ” + DB_NAME() + “)”

print “”
print @printline
GO



Disclaimer:
We hope that the information on these script pages is
valuable to you. Your use of the information contained in these pages,
however, is at your sole risk. All information on these pages is provided
“as -is”, without any warranty, whether express or implied, of its accuracy,
completeness, or fitness for a particular purpose…

Disclaimer Continued

Back to Database Journal Home

Get the Free Newsletter!

Subscribe to Cloud Insider for top news, trends & analysis

Latest Articles