SQL SERVER -Find Total No of a Rows of All Tables in a Given Database

Today one of my friend sreejith (colleague) came and ask me, how to find the total numbers of rows of all tables in a given database.The solution is

SELECT ‘[‘ + Schema_name(t.schema_id) + ‘].[‘ + t.name + ‘]’ AS fulltable_name,
Schema_name(t.schema_id) AS schema_name,
t.name AS table_name,
i.ROWS
FROM sys.tables AS t
INNER JOIN sys.sysindexes AS i
ON t.object_id = i.id
AND i.indid < 2

print

Leave a Reply

Your email address will not be published. Required fields are marked *


× 5 = forty five