Created
May 23, 2022 19:58
-
-
Save Ninjanaut/faef20d8f5a7200b6f88658b3fa383c3 to your computer and use it in GitHub Desktop.
Get table sizes from Azure SQL database
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
-- https://dataedo.com/kb/query/azure-sql/list-of-tables-by-their-size | |
-- Get table sizes from Azure SQL database | |
select schema_name(tab.schema_id) + '.' + tab.name as [table], | |
cast(sum(spc.used_pages * 8)/1024.00/1024.00 as numeric(36, 2)) as used_gb, | |
cast(sum(spc.total_pages * 8)/1024.00/1024.00 as numeric(36, 2)) as allocated_gb | |
from sys.tables tab | |
inner join sys.indexes ind | |
on tab.object_id = ind.object_id | |
inner join sys.partitions part | |
on ind.object_id = part.object_id and ind.index_id = part.index_id | |
inner join sys.allocation_units spc | |
on part.partition_id = spc.container_id | |
group by schema_name(tab.schema_id) + '.' + tab.name | |
order by sum(spc.used_pages) desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment