Friday, October 2, 2015

Table Row Count for particular schema

Query for Table Row Count for particular schema

SELECT
    t.NAME as TableName,
    p.rows as RowCounts
FROM
    sys.tables t
INNER JOIN
    sys.schemas s ON t.schema_id = s.schema_id
INNER JOIN    
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
WHERE
    t.is_ms_shipped = 0 AND s.Name='Staging'
GROUP BY
    t.NAME, s.Name, p.Rows
ORDER BY
    s.Name, t.Name

No comments:

Post a Comment