我在这里查询以查找没有主键的表的列表:
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]
它返回一个表列表,但是我如何对该列表中每个表的记录数进行行计数。
INNER JOIN
sys.partitions p ON sys.indexes.object_id = p.OBJECT_ID AND sys.indexes.index_id = p.index_id
然后可以选择P.[rows]作为[记录数]