SQL Server: Number of 8K Pages Used by a Table and/or Database

Viewed 15577

Can I use T-SQL to show me the number of 8K pages that a table is using to store its rows?

Also, can I see the number of 8K pages that a database is using?

2 Answers

One more way from SQLSERVER2012 with out showing count of rows..My search for some question lead me to here and i updated the answer with the one i used

select 
object_name(object_id) as 'tablename',
count(*) as 'totalpages',
sum(Case when is_allocated=0 then 1 else 0 end) as 'unusedPages',
sum(Case when is_allocated=1 then 1 else 0 end) as 'usedPages'
from sys.dm_db_database_page_allocations(db_id(),null,null,null,'DETAILED')
group by
object_name(object_id)
Related