如果您使用的是SQL Server 2005或更高版本 (很遗憾,您没有指定要使用的SQL Server 版本
),则此查询应为您提供以下信息:
SELECt TableName = t.NAME, TableSchema = s.Name, RowCounts = p.rowsFROM sys.tables tINNER JOIN sys.schemas s ON t.schema_id = s.schema_idINNER JOIN sys.indexes i ON t.OBJECT_ID = i.object_idINNER JOIN sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_idWHERe t.is_ms_shipped = 0GROUP BY t.NAME, s.Name, p.RowsORDER BY s.Name, t.Name
产生的输出类似(来自
AdventureWorks):
TableName TableSchema RowCountsAWBuildVersion dbo 1DatabaseLog dbo 1597ErrorLog dbo 0Department HumanResources 16Employee HumanResources 290JobCandidate HumanResources 13AddressPerson19614AddressType Person 6... and so on......



