How to get the data space of a table in Azure sql database

Bigiron 110 Reputation points
2023-05-30T15:30:36.6466667+00:00

Hi All,

In traditional On Premises SQL Database using SSMS we can right click on the table Properties>Storage and get the Data Space information, how to get the same in Azure SQL Database. Please advice.

Thanks

Azure SQL Database
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,713 questions
0 comments No comments
{count} votes

Accepted answer
  1. Alberto Morillo 32,886 Reputation points MVP
    2023-05-30T15:39:08.83+00:00

    This query gives size of each table in a given database.

    select obj.name, sum(reserved_page_count) * 8.0 as "size in KB" from sys.dm_db_partition_stats part, sys.objects obj where part.object_id = obj.object_id group by obj.name
    
    8 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Nick Ryan 216 Reputation points
    2024-04-17T04:05:43.8366667+00:00

    That one didn't quite work for me but it was a good starting point. Thanks for the idea. My issue was around the fact that my DB has lots of different Schema and the same table name can occur in more than one especially as many of the tables are system versioned.

    I also thought it was a good idea to return the row count.

    select sch.name + '.' + obj.name AS "Table Name",
           sum(reserved_page_count) * 8.0 as "size in KB",
    	   sum(CASE WHEN part.index_id IN( 0,1 ) THEN part.row_count ELSE 0 END) AS "Rows"
    from sys.dm_db_partition_stats part
    JOIN sys.objects obj ON obj.object_id = part.object_id
    JOIN sys.schemas sch ON sch.schema_id = obj.schema_id
    group by sch.name + '.' + obj.name;
    
    0 comments No comments