我打算列出我的数据库中所有没有记录的表。和大多数情况一样,我使用了SP_MSforeachtable,例如:EXEC sys.sp_MSforeachtable 'if (select Count(*) from ?) = 0 select ''?'' ,Count(*) from ? ' 现在我有很多结果集需要统计。 我知道处理表格还有其他方法,但是我认为获取 sys.sp_MSforeachtable(或任何SP)结果集的计数 可能会很有用。 如果有办法将所有这些结果集合并,我将不胜感激。
你可以使用这个查询来提取所需的信息。SELECT T.name, ST.row_count FROM SYS.tables T INNER JOIN SYS.dm_db_partition_stats ST ON T.object_id = ST.object_id WHERE ST.row_count = 0
sys.dm_db_partition_stats
DMV 中查询row_count
列。 - Serg