Wednesday, April 14, 2010

Display row count for all SQL tables

The following T-SQL script returns the number of rows in each table for a database.


SELECT '[' + SCHEMA_NAME(t.schema_id) + '].[' + t.name + ']' AS [Full Table Name], SCHEMA_NAME(t.schema_id) AS [Schema Name], t.name AS [Table Name],

i.rows AS [Row Count] FROM sys.tables AS t INNER JOIN

sys.sysindexes AS i ON t.object_id = i.id AND i.indid < 2
WHERE (t.type = 'U')
   
 
Sample Output:
 
Displaying row count for all tables
 

No comments:

Post a Comment