SELECT
t.NAME AS TableName,
s.Name AS SchemaName,
p.rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
CAST(ROUND(((SUM(a.total_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS TotalSpaceMB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
CAST(ROUND(((SUM(a.used_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS UsedSpaceMB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB,
CAST(ROUND(((SUM(a.total_pages) - SUM(a.used_pages)) * 8) / 1024.00, 2) AS NUMERIC(36, 2)) AS UnusedSpaceMB
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
t.Name
Friday, 19 July 2019
SQL Server: Get size of all tables in database
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2019
(79)
-
▼
July
(21)
- TFS creates a $tf folder with gigabytes of .gz fil...
- How to clear Windows File Cache?
- Team Foundation Server Power Tools December 2011
- How to stream a video file to play on the browser,...
- What is the best value for Fill Factor in SQL Server?
- taskkill
- Use command-line parameters to install Visual Studio
- Lost Filezilla Server administration password
- Start and Stop Windows Azure VMs According to Time...
- SQL Server: Get size of all tables in database
- MySQL: how to get records with count > 1?
- How to use GROUP BY to concatenate strings in MySQL?
- ImageMagick Mogrify
- Reindexing Data with Elasticsearch
- SELECT INTO
- Cursor Overview
- DECLARE MySQL Variable
- How to declare a variable in MySQL?
- MySQL Stored Procedure Variables
- MySQL Cursor
- Fetch cursor to two variables : Cursor Fetch « Cur...
-
▼
July
(21)
No comments:
Post a Comment
Note: only a member of this blog may post a comment.