question

srinnippu-1270 avatar image
0 Votes"
srinnippu-1270 asked DanGuzman answered

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

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
image.png (10.4 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DanGuzman avatar image
0 Votes"
DanGuzman answered

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;


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.