Created
April 27, 2025 14:06
-
-
Save OIegZolotarev/9c70b48ad70c61f67b614abdf7738ab2 to your computer and use it in GitHub Desktop.
Как подглядеть размер таблиц базы на MS SQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE <имя базы на серваке sql>; | |
GO | |
SELECT | |
t.Name AS TableName, | |
s.Name AS SchemaName, | |
p.Rows AS RowCounts, | |
SUM(a.total_pages) * 8 AS TotalSpaceKB, | |
SUM(a.used_pages) * 8 AS UsedSpaceKB, | |
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB | |
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 | |
LEFT OUTER JOIN sys.schemas s ON t.schema_id = s.schema_id | |
WHERE | |
t.Name NOT LIKE 'dt%' | |
AND t.is_ms_shipped = 0 | |
AND i.object_id > 255 | |
GROUP BY | |
t.Name, s.Name, p.Rows | |
ORDER BY | |
SUM(a.used_pages) * 8 | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment