Home   Subscribe   Linkedin
  Archive Contact  

Counting number of rows in all the tables in a database in one query

If you want to count the number of rows across all the tables in a database ,select count(*) for all the tables is quite inefficient method.Better approach is as under

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

 

Posted by: Rishabh Toshniwal

Categories: MySQL, SQL SERVER

Tags: