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

后端 未结 2 1894
情歌与酒
情歌与酒 2020-12-16 14:36

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条回答
  •  太阳男子
    2020-12-16 14:49

    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)
    

提交回复
热议问题