Sayfalar

25 Şubat 2014 Salı

Getting Tables Row Counts From MSSQL Database

This blog explain how to write query for getting row count per table. This query show  fullness rate of tables.

SQL 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
    --  and sOBJ.name like '%emp%'
GROUP BY
      sOBJ.schema_id
      , sOBJ.name
ORDER BY [RowCount]

Hiç yorum yok:

Yorum Gönder