Created
March 23, 2018 15:09
-
-
Save Charmatzis/d446b4dafdd21080c797b2b882ce3cc2 to your computer and use it in GitHub Desktop.
getallocated_page_page_id of a table MS SQL Server
This file contains 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
WITH dataCTE | |
AS | |
( | |
SELECT allocated_page_page_id, next_page_page_id, previous_page_page_id | |
FROM sys.dm_db_database_page_allocations(DB_ID(), OBJECT_ID('dbo.TEMP_POS_TERR'),1, NULL, 'DETAILED') | |
WHERE is_allocated = 1 | |
AND page_type_desc = 'DATA_PAGE' | |
) | |
,pageCTE | |
AS | |
( | |
SELECT allocated_page_page_id, next_page_page_id, 1 AS page_sequence | |
FROM dataCTE | |
WHERE previous_page_page_id IS NULL | |
UNION ALL | |
SELECT d.allocated_page_page_id, d.next_page_page_id, p.page_sequence +1 AS page_sequence | |
FROM pageCTE AS p | |
JOIN dataCTE AS D | |
ON d.allocated_page_page_id = p.next_page_page_id | |
) | |
SELECT allocated_page_page_id, page_sequence | |
FROM pageCTE | |
ORDER BY page_sequence | |
option (maxrecursion 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment