Friday, June 21, 2013

SQL Query for get all tables name and table rows

==>> In this article I am posting SQL Query for get all tables name and table rows. Some time we need to get all table name and it's rows so this query will heplfull.


SELECT  scs.name + '.' + tas.name TableNames ,
        SUM(pas.rows) RowsCounted
FROM    sys.tables tas
        INNER JOIN sys.partitions pas ON pas.OBJECT_ID = tas.OBJECT_ID
        INNER JOIN sys.schemas scs ON tas.schema_id = scs.schema_id
WHERE   tas.is_ms_shipped = 0
        AND pas.index_id IN ( 1, 0 )
GROUP BY scs.name ,
        tas.name
ORDER BY SUM(pas.rows) DESC



Hope this post will help you...

No comments:

Post a Comment