Technical Article

Row count of all tables

,

Quick and accurate method to get the row count of each table in a given database. Execution time is dependent on the number of rows in each table.


-- Girish (gvphubli)

-- on busy server you can uncomment below line of code
-- SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

CREATE TABLE [dbo].[RowCount](
TableName VARCHAR(100),
[Rows] INT
)

GO

sp_MSForEachTable 'INSERT INTO [dbo].[RowCount] SELECT ''?'', COUNT(1) FROM ?'

SELECT * FROM [dbo].[RowCount] ORDER BY Rows

DROP TABLE [dbo].[RowCount]

Rate

2.25 (4)

You rated this post out of 5. Change rating

Share

Share

Rate

2.25 (4)

You rated this post out of 5. Change rating