Skip to content

Commit 228dbfb

Browse files
Merge pull request #34627 from rwestMSFT/rw-0707-fix-10124
Refresh sys.internal_tables article (PR 10124)
2 parents 92a630a + 42e9789 commit 228dbfb

1 file changed

Lines changed: 153 additions & 149 deletions

File tree

docs/relational-databases/system-catalog-views/sys-internal-tables-transact-sql.md

Lines changed: 153 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "sys.internal_tables (Transact-SQL)"
33
description: sys.internal_tables (Transact-SQL)
44
author: rwestMSFT
55
ms.author: randolphwest
6-
ms.date: "03/14/2019"
6+
ms.date: 07/07/2025
77
ms.service: sql
88
ms.subservice: system-objects
99
ms.topic: "reference"
@@ -19,153 +19,157 @@ dev_langs:
1919
- "TSQL"
2020
---
2121
# sys.internal_tables (Transact-SQL)
22+
2223
[!INCLUDE [SQL Server](../../includes/applies-to-version/sqlserver.md)]
2324

24-
Returns one row for each object that is an internal table. Internal tables are automatically generated by [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] to support various features. For example, when you create a primary XML index, [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] automatically creates an internal table to persist the shredded XML document data. Internal tables appear in the **sys** schema of every database and have unique, system-generated names that indicate their function, for example, **xml_index_nodes_2021582240_32001** or **queue_messages_1977058079**
25-
26-
Internal tables do not contain user-accessible data, and their schema are fixed and unalterable. You cannot reference internal table names in [!INCLUDE[tsql](../../includes/tsql-md.md)] statements. For example, you cannot execute a statement such as SELECT \* FROM *\<sys.internal_table_name>*. However, you can query catalog views to see the metadata of internal tables.
27-
28-
29-
|Column name|Data type|Description|
30-
|-----------------|---------------|-----------------|
31-
|**\<Columns inherited from sys.objects>**||For a list of columns that this view inherits, see [sys.objects &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/sys-objects-transact-sql.md).|
32-
|**internal_type**|**tinyint**|Type of the internal table:<br /><br /> 3 = **query_disk_store_query_hints**<br /><br /> 4 = **query_disk_store_query_template_parameterization**<br /><br /> 6 = **query_disk_store_wait_stats**<br /><br /> 201 = **queue_messages**<br /><br /> 202 = **xml_index_nodes**<br /><br /> 203 = **fulltext_catalog_freelist**<br /><br /> 205 = **query_notification**<br /><br /> 206 = **service_broker_map**<br /><br /> 207 = **extended_indexes** (such as a spatial index)<br /><br /> 208 = **filestream_tombstone**<br /><br /> 209 = **change_tracking**<br /><br /> 210 = **tracked_committed_transactions**<br /><br /> 220 = **contained_features**<br /><br /> 225 = **filetable_updates**<br /><br /> 236 = **selective_xml_index_node_table**<br /><br /> 240 = **query_disk_store_query_text**<br /><br /> 241 = **query_disk_store_query**<br /><br /> 242 = **query_disk_store_plan**<br /><br /> 243 = **query_disk_store_runtime_stats**<br /><br /> 244 = **query_disk_store_runtime_stats_interval**<br /><br /> 245 = **query_context_settings**|
33-
|**internal_type_desc**|**nvarchar(60)**|Description of the type of internal table:<br /><br /> QUERY_DISK_STORE_QUERY_HINTS<br /><br /> QUERY_DISK_STORE_QUERY_TEMPLATE_PARAMETERIZATION<br /><br /> QUERY_DISK_STORE_WAIT_STATS<br /><br /> QUEUE_MESSAGES<br /><br /> XML_INDEX_NODES<br /><br /> FULLTEXT_CATALOG_FREELIST<br /><br /> FULLTEXT_CATALOG_MAP<br /><br /> QUERY_NOTIFICATION<br /><br /> SERVICE_BROKER_MAP<br /><br /> EXTENDED_INDEXES<br /><br /> FILESTREAM_TOMBSTONE<br /><br /> CHANGE_TRACKING<br /><br /> TRACKED_COMMITTED_TRANSACTIONS<br /><br /> CONTAINED_FEATURES<br /><br /> FILETABLE_UPDATES<br /><br /> SELECTIVE_XML_INDEX_NODE_TABLE<br /><br /> QUERY_DISK_STORE_QUERY_TEXT<br /><br /> QUERY_DISK_STORE_QUERY<br /><br /> QUERY_DISK_STORE_PLAN<br /><br /> QUERY_DISK_STORE_RUNTIME_STATS<br /><br /> QUERY_DISK_STORE_RUNTIME_STATS_INTERVAL<br /><br /> QUERY_CONTEXT_SETTINGS|
34-
|**parent_id**|**int**|ID of the parent, regardless of whether it is schema-scoped or not. Otherwise, 0 if there is no parent.<br /><br /> **queue_messages** = **object_id** of queue<br /><br /> **xml_index_nodes** = **object_id** of the xml index<br /><br /> **fulltext_catalog_freelist** = **fulltext_catalog_id** of the full-text catalog<br /><br /> **fulltext_index_map** = **object_id** of the full-text index<br /><br /> **query_notification**, or **service_broker_map** = 0<br /><br /> **extended_indexes** = **object_id** of an extended index, such as a spatial index<br /><br /> **object_id** of the table for which table tracking is enabled = **change_tracking**|
35-
|**parent_minor_id**|**int**|Minor ID of the parent.<br /><br /> **xml_index_nodes** = **index_id** of the XML index<br /><br /> **extended_indexes** = **index_id** of an extended index, such as a spatial index<br /><br /> 0 = **queue_messages**, **fulltext_catalog_freelist**, **fulltext_index_map**, **query_notification**, **service_broker_map**, or **change_tracking**|
36-
|**lob_data_space_id**|**int**|Non-zero value is the ID of data space (filegroup or partition-scheme) that holds the large object (LOB) data for this table.|
37-
|**filestream_data_space_id**|**int**|Reserved for future use.|
38-
39-
## Permissions
40-
[!INCLUDE[ssCatViewPerm](../../includes/sscatviewperm-md.md)] For more information, see [Metadata Visibility Configuration](../../relational-databases/security/metadata-visibility-configuration.md).
41-
42-
## Remarks
43-
Internal tables are placed on the same filegroup as the parent entity. You can use the catalog query shown in Example F below to return the number of pages internal tables consume for in-row, out-of-row, and large object (LOB) data.
44-
45-
You can use the [sp_spaceused](../../relational-databases/system-stored-procedures/sp-spaceused-transact-sql.md) system procedure to return space usage data for internal tables. **sp_spaceused** reports internal table space in the following ways:
46-
47-
- When a queue name is specified, the underlying internal table associated with the queue is referenced and its storage consumption is reported.
48-
49-
- Pages that are used by the internal tables of XML indexes, spatial indexes, and full-text indexes are included in the **index_size** column. When a table or indexed view name is specified, the pages for the XML indexes, spatial indexes, and full-text indexes for that object are included in the columns **reserved** and **index_size**.
50-
51-
## Examples
52-
The following examples demonstrate how to query internal table metadata by using catalog views.
53-
54-
### A. Show internal tables that inherit columns from the sys.objects catalog view
55-
56-
```
57-
SELECT * FROM sys.objects WHERE type = 'IT';
58-
```
59-
60-
### B. Return all internal table metadata (including that which is inherited from sys.objects)
61-
62-
```
63-
SELECT * FROM sys.internal_tables;
64-
```
65-
66-
### C. Return internal table columns and column data types
67-
68-
```
69-
SELECT SCHEMA_NAME(itab.schema_id) AS schema_name
70-
,itab.name AS internal_table_name
71-
,typ.name AS column_data_type
72-
,col.*
73-
FROM sys.internal_tables AS itab
74-
JOIN sys.columns AS col ON itab.object_id = col.object_id
75-
JOIN sys.types AS typ ON typ.user_type_id = col.user_type_id
76-
ORDER BY itab.name, col.column_id;
77-
```
78-
79-
### D. Return internal table indexes
80-
81-
```
82-
SELECT SCHEMA_NAME(itab.schema_id) AS schema_name
83-
, itab.name AS internal_table_name
84-
, idx.*
85-
FROM sys.internal_tables AS itab
86-
JOIN sys.indexes AS idx ON itab.object_id = idx.object_id
87-
ORDER BY itab.name, idx.index_id;
88-
```
89-
90-
### E. Return internal table statistics
91-
92-
```
93-
SELECT SCHEMA_NAME(itab.schema_id) AS schema_name
94-
,itab.name AS internal_table_name
95-
, s.*
96-
FROM sys.internal_tables AS itab
97-
JOIN sys.stats AS s ON itab.object_id = s.object_id
98-
ORDER BY itab.name, s.stats_id;
99-
```
100-
101-
### F. Return internal table partition and allocation unit information
102-
103-
```
104-
SELECT SCHEMA_NAME(itab.schema_id) AS schema_name
105-
,itab.name AS internal_table_name
106-
,idx.name AS heap_or_index_name
107-
,p.*
108-
,au.*
109-
FROM sys.internal_tables AS itab
110-
JOIN sys.indexes AS idx
111-
-- JOIN to the heap or the clustered index
112-
ON itab.object_id = idx.object_id AND idx.index_id IN (0,1)
113-
JOIN sys.partitions AS p
114-
ON p.object_id = idx.object_id AND p.index_id = idx.index_id
115-
JOIN sys.allocation_units AS au
116-
-- IN_ROW_DATA (type 1) and ROW_OVERFLOW_DATA (type 3) => JOIN to partition's Hobt
117-
-- else LOB_DATA (type 2) => JOIN to the partition ID itself.
118-
ON au.container_id =
119-
CASE au.type
120-
WHEN 2 THEN p.partition_id
121-
ELSE p.hobt_id
122-
END
123-
ORDER BY itab.name, idx.index_id;
124-
```
125-
126-
### G. Return internal table metadata for XML indexes
127-
128-
```
129-
SELECT t.name AS parent_table
130-
,t.object_id AS parent_table_id
131-
,it.name AS internal_table_name
132-
,it.object_id AS internal_table_id
133-
,xi.name AS primary_XML_index_name
134-
,xi.index_id as primary_XML_index_id
135-
FROM sys.internal_tables AS it
136-
JOIN sys.tables AS t
137-
ON it.parent_id = t.object_id
138-
JOIN sys.xml_indexes AS xi
139-
ON it.parent_id = xi.object_id
140-
AND it.parent_minor_id = xi.index_id
141-
WHERE it.internal_type_desc = 'XML_INDEX_NODES';
142-
GO
143-
```
144-
145-
### H. Return internal table metadata for Service Broker queues
146-
147-
```
148-
SELECT q.name AS queue_name
149-
,q.object_id AS queue_id
150-
,it.name AS internal_table_name
151-
,it.object_id AS internal_table_id
152-
FROM sys.internal_tables AS it
153-
JOIN sys.service_queues AS q ON it.parent_id = q.object_id
154-
WHERE it.internal_type_desc = 'QUEUE_MESSAGES';
155-
GO
156-
```
157-
158-
## I. Return internal table metadata for all Service Broker services
159-
160-
```
161-
SELECT *
162-
FROM tempdb.sys.internal_tables
163-
WHERE internal_type_desc = 'SERVICE_BROKER_MAP';
164-
GO
165-
```
166-
167-
## See Also
168-
[Catalog Views &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/catalog-views-transact-sql.md)
169-
[Object Catalog Views &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/object-catalog-views-transact-sql.md)
170-
171-
25+
Returns one row for each object that is an internal table. Internal tables are automatically generated by [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] to support various features. For example, when you create a primary XML index, [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] automatically creates an internal table to persist the shredded XML document data. Internal tables appear in the `sys` schema of every database and have unique, system-generated names that indicate their function, for example, `xml_index_nodes_2021582240_32001` or `queue_messages_1977058079`.
26+
27+
| Column name | Data type | Description |
28+
| --- | --- | --- |
29+
| **Columns inherited from `sys.objects`** | | For a list of columns that this view inherits, see [sys.objects](sys-objects-transact-sql.md). |
30+
| `internal_type` | **tinyint** | Type of the internal table:<br /><br />3 = `QUERY_DISK_STORE_QUERY_HINTS`<br />4 = `QUERY_DISK_STORE_QUERY_TEMPLATE_PARAMETERIZATION`<br />6 = `QUERY_DISK_STORE_WAIT_STATS`<br />201 = `QUEUE_MESSAGES`<br />202 = `XML_INDEX_NODES`<br />203 = `FULLTEXT_CATALOG_FREELIST`<br />204 = `FULLTEXT_INDEX_MAP`<br />205 = `QUERY_NOTIFICATION`<br />206 = `SERVICE_BROKER_MAP`<br />207 = `EXTENDED_INDEXES` (such as a spatial index)<br />208 = `FILESTREAM_TOMBSTONE`<br />209 = `CHANGE_TRACKING`<br />210 = `TRACKED_COMMITTED_TRANSACTIONS`<br />220 = `CONTAINED_FEATURES`<br />225 = `FILETABLE_UPDATES`<br />236 = `SELECTIVE_XML_INDEX_NODE_TABLE`<br />240 = `QUERY_DISK_STORE_QUERY_TEXT`<br />241 = `QUERY_DISK_STORE_QUERY`<br />242 = `QUERY_DISK_STORE_PLAN`<br />243 = `QUERY_DISK_STORE_RUNTIME_STATS`<br />244 = `QUERY_DISK_STORE_RUNTIME_STATS_INTERVAL`<br />245 = `QUERY_CONTEXT_SETTINGS` |
31+
| `internal_type_desc` | **nvarchar(60)** | Description of the type of internal table:<br /><br />`QUERY_DISK_STORE_QUERY_HINTS`<br />`QUERY_DISK_STORE_QUERY_TEMPLATE_PARAMETERIZATION`<br />`QUERY_DISK_STORE_WAIT_STATS`<br />`QUEUE_MESSAGES`<br />`XML_INDEX_NODES`<br />`FULLTEXT_CATALOG_FREELIST`<br />`FULLTEXT_INDEX_MAP`<br />`QUERY_NOTIFICATION`<br />`SERVICE_BROKER_MAP`<br />`EXTENDED_INDEXES`<br />`FILESTREAM_TOMBSTONE`<br />`CHANGE_TRACKING`<br />`TRACKED_COMMITTED_TRANSACTIONS`<br />`CONTAINED_FEATURES`<br />`FILETABLE_UPDATES`<br />`SELECTIVE_XML_INDEX_NODE_TABLE`<br />`QUERY_DISK_STORE_QUERY_TEXT`<br />`QUERY_DISK_STORE_QUERY`<br />`QUERY_DISK_STORE_PLAN`<br />`QUERY_DISK_STORE_RUNTIME_STATS`<br />`QUERY_DISK_STORE_RUNTIME_STATS_INTERVAL`<br />`QUERY_CONTEXT_SETTINGS` |
32+
| `parent_id` | **int** | ID of the parent, regardless of whether it's schema-scoped or not. Otherwise, `0` if there's no parent.<br /><br />`queue_messages` = `object_id` of queue<br /><br />`xml_index_nodes` = `object_id` of the XML index<br /><br />`fulltext_catalog_freelist` = `fulltext_catalog_id` of the full-text catalog<br /><br />`fulltext_index_map` = `object_id` of the full-text index<br /><br />`query_notification`, or `service_broker_map` = `0`<br /><br />`extended_indexes` = `object_id` of an extended index, such as a spatial index<br /><br />`object_id` of the table for which table tracking is enabled = `change_tracking` |
33+
| `parent_minor_id` | **int** | Minor ID of the parent.<br /><br />`xml_index_nodes` = `index_id` of the XML index<br />`extended_indexes` = `index_id` of an extended index, such as a spatial index<br /><br />`0` = `queue_messages`, `fulltext_catalog_freelist`, `fulltext_index_map`, `query_notification`, `service_broker_map`, or `change_tracking` |
34+
| `lob_data_space_id` | **int** | Non-zero value is the ID of data space (filegroup or partition-scheme) that holds the large object (LOB) data for this table. |
35+
| `filestream_data_space_id` | **int** | Reserved for future use. |
36+
37+
Internal tables don't contain user-accessible data, and their schema are fixed and unalterable. You can't reference internal table names in [!INCLUDE [tsql](../../includes/tsql-md.md)] statements. For example, you can't execute a statement such as `SELECT * FROM <sys.internal_table_name>`. However, you can query catalog views to see the metadata of internal tables.
38+
39+
## Permissions
40+
41+
[!INCLUDE [ssCatViewPerm](../../includes/sscatviewperm-md.md)] For more information, see [Metadata Visibility Configuration](../security/metadata-visibility-configuration.md).
42+
43+
## Remarks
44+
45+
Internal tables are placed on the same filegroup as the parent entity. You can use the catalog query shown in [Example F](#f-return-internal-table-partition-and-allocation-unit-information) to return the number of pages internal tables consume for in-row, out-of-row, and large object (LOB) data.
46+
47+
You can use the [sp_spaceused](../system-stored-procedures/sp-spaceused-transact-sql.md) system procedure to return space usage data for internal tables. `sp_spaceused` reports internal table space in the following ways:
48+
49+
- When a queue name is specified, the underlying internal table associated with the queue is referenced and its storage consumption is reported.
50+
51+
- Pages that are used by the internal tables of XML indexes, spatial indexes, and full-text indexes are included in the `index_size` column. When a table or indexed view name is specified, the pages for the XML indexes, spatial indexes, and full-text indexes for that object are included in the columns `reserved` and `index_size`.
52+
53+
## Examples
54+
55+
The following examples demonstrate how to query internal table metadata by using catalog views.
56+
57+
### A. Show internal tables that inherit columns from the sys.objects catalog view
58+
59+
```sql
60+
SELECT * FROM sys.objects WHERE type = 'IT';
61+
```
62+
63+
### B. Return all internal table metadata (including that which is inherited from sys.objects)
64+
65+
```sql
66+
SELECT * FROM sys.internal_tables;
67+
```
68+
69+
### C. Return internal table columns and column data types
70+
71+
```sql
72+
SELECT SCHEMA_NAME(itab.schema_id) AS schema_name,
73+
itab.name AS internal_table_name,
74+
typ.name AS column_data_type,
75+
col.*
76+
FROM sys.internal_tables AS itab
77+
INNER JOIN sys.columns AS col
78+
ON itab.object_id = col.object_id
79+
INNER JOIN sys.types AS typ
80+
ON typ.user_type_id = col.user_type_id
81+
ORDER BY itab.name, col.column_id;
82+
```
83+
84+
### D. Return internal table indexes
85+
86+
```sql
87+
SELECT SCHEMA_NAME(itab.schema_id) AS schema_name,
88+
itab.name AS internal_table_name,
89+
idx.*
90+
FROM sys.internal_tables AS itab
91+
INNER JOIN sys.indexes AS idx
92+
ON itab.object_id = idx.object_id
93+
ORDER BY itab.name, idx.index_id;
94+
```
95+
96+
### E. Return internal table statistics
97+
98+
```sql
99+
SELECT SCHEMA_NAME(itab.schema_id) AS schema_name,
100+
itab.name AS internal_table_name,
101+
s.*
102+
FROM sys.internal_tables AS itab
103+
INNER JOIN sys.stats AS s
104+
ON itab.object_id = s.object_id
105+
ORDER BY itab.name, s.stats_id;
106+
```
107+
108+
### F. Return internal table partition and allocation unit information
109+
110+
```sql
111+
SELECT SCHEMA_NAME(itab.schema_id) AS schema_name,
112+
itab.name AS internal_table_name,
113+
idx.name AS heap_or_index_name,
114+
p.*,
115+
au.*
116+
FROM sys.internal_tables AS itab
117+
INNER JOIN sys.indexes AS idx
118+
-- JOIN to the heap or the clustered index
119+
ON itab.object_id = idx.object_id
120+
AND idx.index_id IN (0, 1)
121+
INNER JOIN sys.partitions AS p
122+
ON p.object_id = idx.object_id
123+
AND p.index_id = idx.index_id
124+
INNER JOIN sys.allocation_units AS au
125+
-- IN_ROW_DATA (type 1) and ROW_OVERFLOW_DATA (type 3) => JOIN to partition's Hobt
126+
-- else LOB_DATA (type 2) => JOIN to the partition ID itself.
127+
ON au.container_id = CASE au.type WHEN 2 THEN p.partition_id ELSE p.hobt_id END
128+
ORDER BY itab.name, idx.index_id;
129+
```
130+
131+
### G. Return internal table metadata for XML indexes
132+
133+
```sql
134+
SELECT t.name AS parent_table,
135+
t.object_id AS parent_table_id,
136+
it.name AS internal_table_name,
137+
it.object_id AS internal_table_id,
138+
xi.name AS primary_XML_index_name,
139+
xi.index_id AS primary_XML_index_id
140+
FROM sys.internal_tables AS it
141+
INNER JOIN sys.tables AS t
142+
ON it.parent_id = t.object_id
143+
INNER JOIN sys.xml_indexes AS xi
144+
ON it.parent_id = xi.object_id
145+
AND it.parent_minor_id = xi.index_id
146+
WHERE it.internal_type_desc = 'XML_INDEX_NODES';
147+
GO
148+
```
149+
150+
### H. Return internal table metadata for Service Broker queues
151+
152+
```sql
153+
SELECT q.name AS queue_name,
154+
q.object_id AS queue_id,
155+
it.name AS internal_table_name,
156+
it.object_id AS internal_table_id
157+
FROM sys.internal_tables AS it
158+
INNER JOIN sys.service_queues AS q
159+
ON it.parent_id = q.object_id
160+
WHERE it.internal_type_desc = 'QUEUE_MESSAGES';
161+
GO
162+
```
163+
164+
## I. Return internal table metadata for all Service Broker services
165+
166+
```sql
167+
SELECT * FROM tempdb.sys.internal_tables
168+
WHERE internal_type_desc = 'SERVICE_BROKER_MAP';
169+
GO
170+
```
171+
172+
## Related content
173+
174+
- [System catalog views (Transact-SQL)](catalog-views-transact-sql.md)
175+
- [Object catalog views (Transact-SQL)](object-catalog-views-transact-sql.md)

0 commit comments

Comments
 (0)