Is it easier way to find row count of each table in SQLSERVER
Yes, earlier i have added post which is custom dynamic tsql to get row count of each table in sqlserver. Even SQLServer system tables itself store the result of each row count of all tables of all databases.
It can be easily identify using sys.tables and partition table. This is not a innovative but it is just a smartness at your work
SELECT
SCHEMA_NAME(schema_id),
t.name AS Table_Name,
SUM(p.[rows]) AS [TotalRowCount]
FROM
sys.tables t
JOIN sys.partitions p ON t.object_id = p.object_id
AND p.index_id IN ( 0, 1 )
GROUP BY SCHEMA_NAME(schema_id), t.name
having
SUM(p.[rows]) > 1
to get all tables remove having clause from above query you will be able to see the result of each table. Right now it is returning the only those tables whose result is more than 1.
No comments:
Post a Comment