Table of Contents

Inspecting database file contents

Database pages

SQL Server 2012 and beyond

Pages in a database are returned by the sys.dm_db_database_page_allocations DMF. Parameters:

SELECT * 
FROM sys.dm_db_database_page_allocations(
  DB_ID(), OBJECT_ID('[dbo].[Test]'), NULL, NULL, 'DETAILED'
)
WHERE is_allocated = 1;

Before SQL Server 2012

DBCC IND is available in earlier versions and returns a subset of the information in sys.dm_db_database_page_allocations. Parameters:

DBCC IND(7, 'dbo.Test', 1) WITH TABLERESULTS

Correspondence to columns in sys.dm_db_database_page_allocations:

DBCC IND column name Returned in sys.dm_db_database_page_allocations as
PageFID allocated_page_file_id
PagePID allocated_page_page_id
IAMFID allocated_page_iam_file_id
IAMPID allocated_page_iam_page_id
ObjectID object_id
IndexID index_id
PartitionNumber partition_id
PartitionID rowset_id
iam_chain_type allocation_unit_type_desc
PageType page_type
IndexLevel page_level
NextPageFID next_page_file_id
NextPagePID next_page_page_id
PrevPageFID previous_page_file_id
PrevPagePID previous_page_page_id

To cache DBCC IND output for reuse:

IF OBJECT_ID('tempdb..#dbccInd') IS NOT NULL
  DROP TABLE #dbccInd
 
CREATE TABLE #dbccInd (
  allocated_page_file_id SMALLINT         -- PageFID
, allocated_page_page_id INT              -- PagePID
, allocated_page_iam_file_id SMALLINT     -- IAMFID
, allocated_page_iam_page_id INT          -- IAMPID
, [object_id] INT                         -- ObjectID
, index_id INT                            -- IndexID
, [partition_id] INT                      -- PartitionNumber
, rowset_id BIGINT                        -- PartitionID
, allocation_unit_type_desc NVARCHAR(60)  -- iam_chain_type
, page_type INT                           -- PageType
, page_level TINYINT                      -- IndexLevel
, next_page_file_id SMALLINT              -- NextPageFID
, next_page_page_id INT                   -- NextPagePID
, previous_page_file_id SMALLINT          -- PrevPageFID
, previous_page_page_id INT               -- PrevPagePID
)
 
INSERT INTO #dbccInd
EXEC ('DBCC IND(7, ''dbo.Test'', 1) WITH TABLERESULTS')
 
--SELECT * FROM #dbccInd

Page contents

Page contents are inspected using DBCC PAGE. Parameters:

To print output to the console, enable trace flag 3604:

DBCC TRACEON (3604)
DBCC PAGE (7, 1, 289,2) 
DBCC TRACEOFF (3604)

To cache output in a table:

IF OBJECT_ID('tempdb..#dbccInd') IS NOT NULL
  DROP TABLE #dbccInd
 
CREATE TABLE #dbccInd (
  [ParentObject] VARCHAR(100)
, [Object] VARCHAR(1000)
, [Field] VARCHAR(100)
, [VALUE] VARCHAR(MAX)
);
 
INSERT INTO #dbccInd
EXEC sp_executesql N'DBCC PAGE (7, 1, 289,2) WITH TABLERESULTS'
 
--SELECT * FROM #dbccInd