Get List of Table by size in Azure SQL Database

Here is a handy sql script to get a list of tables by their size in Azure SQL Database

select schema_name(tab.schema_id) + '.' + tab.name as [tablename],

    cast(sum(spc.used_pages * 8)/1024.00 as numeric(36, 2)) as used_spacemb,

    cast(sum(spc.total_pages * 8)/1024.00 as numeric(36, 2)) as allocated_spacemb

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

 

The columns you will get from this script:

tablename

size_mb

allocated_spacemb