数据库中的计数表在SQL Server中有多个记录

时间:2018-02-12 14:43:18

标签: sql tsql sql-server-2012

是否有任何查询返回记录多行的表的计数?

1 个答案:

答案 0 :(得分:1)

一种方式:

select
    TableName = sc.name +'.'+ ta.name, RowCnt = sum(pa.rows) 
from 
    sys.tables ta
    join sys.partitions pa on pa.object_id = ta.object_id
    join sys.schemas sc on ta.schema_id = sc.schema_id
where 
    ta.is_ms_shipped = 0 
    AND pa.index_id IN (1,0)
group by sc.name,ta.name
having sum(pa.rows) > 0