How to get list of Tables and count of rows from table

Raj0125 511 Reputation points
2022-05-24T13:12:23.947+00:00

Hi,

How to get list of Tables and count of rows from table by writing single Query.

Expected O/P as below

205106-image.png

Azure SQL Database
0 comments No comments
{count} votes

Accepted answer
  1. Dan Guzman 9,201 Reputation points
    2022-05-24T13:43:54.417+00:00

    Below is an example using the object catalog views:

    SELECT s.name AS SchemaName, t.name AS TableName, SUM(p.rows) AS TableRowCount
    FROM sys.schemas AS s
    JOIN sys.tables AS t ON t.schema_id = s.schema_id
    JOIN sys.partitions AS p ON p.object_id = t.object_id
    GROUP BY s.name, t.name
    ORDER BY SchemaName, TableName;
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful