Archive for December, 2009

MSSQL : List all tables with size and row count

By admin - Last updated: Sunday, December 13, 2009

It comes to be very handy while analyzing the database tables.
Here is a quick and dirty script lists all the tables and their rows counts, data size.

DECLARE @table table(Id int IDENTITY(1,1)
, Name varchar(256))

INSERT INTO @table
SELECT b.name + ‘.’+ a.name
FROM sys.tables a INNER JOIN sys.schemas b
ON a.schema_id = b.schema_id

INSERT INTO @table
SELECT ‘-1′

DECLARE @result table( TableName varchar(256)
, TotalRows [...]