如何数据库的表与记录数多少
清理数据库时需要删除一些数据较多的表
sql 能得出 test 数据库中 表与表记录数的的对应关系吗
tablename count
表a 1
表b 2
表c 3
.。。。。
[解决办法]
试试这个:
select o.name,
i.rowcnt as 行数
from sysindexes i
inner join sysobjects o
on i.id = o.id
where o.xtype = 'U'
/*
查询表中总行数
由于sys.dm_db_partition_stats并不是实时更新,所以数据并不能保证是完全准确的。
并且包含了所有分区的数据,2008以后sqlserver对单独的一个表也会认为是一个分区
*/
SELECT Object_schema_name(ddps.object_id) + '.'
+ Object_name(ddps.object_id) AS NAME,
Sum(ddps.row_count) AS row_count
FROM sys.dm_db_partition_stats AS ddps
INNER JOIN sys.indexes ix
ON ix.object_id = ddps.object_id
AND ix.index_id = ddps.index_id
WHERE ix.type_desc IN ( 'CLUSTERED', 'HEAP' )
AND Objectproperty(ddps.object_id, 'IsMSShipped') = 0
GROUP BY ddps.object_id
ORDER BY row_count DESC