SQL Query To Fetch All Data Tables Records Count From A Database

SQL query to fetch all data tables records count from a database.

If the Orchestrator(OC) application performance is not good or slowness is observed then, check the records available in data tables for OC DB. By analyzing the same, it can be suggested if DB maintenance is required or not.

For checking the count of records in data tables in a database, execute the below query & get the list of tables easily.

Query:

SELECT

   QUOTENAME(SCHEMA_NAME(sOBJ.schema_id)) + '.' + QUOTENAME(sOBJ.name) AS [TableName]

   , SUM(sPTN.Rows) AS [RowCount]

FROM 

   sys.objects AS sOBJ

   INNER JOIN sys.partitions AS sPTN

      ON sOBJ.object_id = sPTN.object_id

WHERE

   sOBJ.type = 'U'

   AND sOBJ.is_ms_shipped = 0x0

   AND index_id < 2 -- 0:Heap, 1:Clustered

GROUP BY 

   sOBJ.schema_id

   , sOBJ.name

ORDER BY [TableName]