可以使用以下查询语句来获取当前数据库表的行数以及占用空间(MB):

SELECT t.NAME AS TableName, p.rows AS RowCounts, CAST(SUM(a.total_pages) / 1024.00 AS DECIMAL(18, 2)) AS TotalSpaceMB FROM sys.tables t INNER JOIN sys.indexes i ON t.OBJECT_ID = i.object_id INNER JOIN sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id INNER JOIN sys.allocation_units a ON p.partition_id = a.container_id WHERE t.NAME NOT LIKE 'dt%' AND t.is_ms_shipped = 0 AND i.OBJECT_ID > 255 GROUP BY t.NAME, p.Rows ORDER BY t.NAME

这将返回一个表,其中包含每个表的名称、行数和占用空间(以MB为单位)

mssql查询出来当前数据库表的行数以及占用空间MB

原文地址: https://www.cveoy.top/t/topic/ebJs 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录