如何对 SQL Server 中的表列表中的每个表进行行计数?

问题描述 投票:0回答:1

我在这里查询以查找没有主键的表的列表:

select schema_name(tab.schema_id) as [schema_name], 
    tab.[name] as table_name
from sys.tables tab
    left outer join sys.indexes pk
        on tab.object_id = pk.object_id 
        and pk.is_primary_key = 1
where pk.object_id is null
order by schema_name(tab.schema_id),
    tab.[name]

它返回一个表列表,但是我如何对该列表中每个表的记录数进行行计数。

sql
1个回答
0
投票
INNER JOIN 
    sys.partitions p ON sys.indexes.object_id = p.OBJECT_ID AND sys.indexes.index_id = p.index_id

然后可以选择P.[rows]作为[记录数]

© www.soinside.com 2019 - 2024. All rights reserved.