SQL Server 2008中是否有办法找到数据库中行数最多的表?
答案 0 :(得分:36)
这会让你走近:
SELECT
[TableName] = so.name,
[RowCount] = MAX(si.rows)
FROM
sysobjects so,
sysindexes si
WHERE
so.xtype = 'U'
AND
si.id = OBJECT_ID(so.name)
GROUP BY
so.name
ORDER BY
2 DESC
答案 1 :(得分:9)
这基本上与Chris Ballance提供的T-SQL相同,但使用新的对象目录视图而不是兼容性视图:
SELECT SchemaName = schemas.[name],
TableName = tables.[name],
IndexName = indexes.[name],
IndexType =
CASE indexes.type
WHEN 0 THEN 'Heap'
WHEN 1 THEN 'Clustered'
END,
IndexPartitionCount = partition_info.PartitionCount,
IndexTotalRows = partition_info.TotalRows
FROM sys.tables
JOIN sys.indexes
ON tables.object_id = indexes.object_id
AND indexes.type IN ( 0, 1 )
JOIN ( SELECT object_id, index_id, PartitionCount = COUNT(*), TotalRows = SUM(rows)
FROM sys.partitions
GROUP BY object_id, index_id
) partition_info
ON indexes.object_id = partition_info.object_id
AND indexes.index_id = partition_info.index_id
JOIN sys.schemas ON tables.schema_id = schemas.schema_id
ORDER BY SchemaName, TableName;
答案 2 :(得分:0)
我只是自定义我的SSMS 2008以显示以下附加列 对于表格 - 行数 - 使用的数据空间(KB)
用于数据库 - 主要数据位置 - 上次备份日期 - 创建日期 ....
在没有打开查询的情况下大部分时间对我工作更快,我只需点击列标题即可转到ASC或DESC