Friday 11 May 2012

(SQL SERVER) To find the row count of all tables in a database


Execute the below query to find the table names and the row count of the corresponding tables in a database.


SELECT
    sysobjects.Name
    , sysindexes.Rows
FROM
    sysobjects
    INNER JOIN sysindexes
    ON sysobjects.id = sysindexes.id
WHERE
    type = 'U'
    AND sysindexes.IndId < 2
ORDER BY
    sysobjects.name


The row count of a particular table can be found by executing
  
exec sp_spaceused 'tablename'