You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
|**\<Columns inherited from sys.objects>**||For a list of columns that this view inherits, see [sys.objects (Transact-SQL)](../../relational-databases/system-catalog-views/sys-objects-transact-sql.md).|
|**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
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). |
|`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*FROMsys.objectsWHERE type ='IT';
61
+
```
62
+
63
+
### B. Return all internal table metadata (including that which is inherited from sys.objects)
64
+
65
+
```sql
66
+
SELECT*FROMsys.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.nameAS internal_table_name,
74
+
typ.nameAS column_data_type,
75
+
col.*
76
+
FROMsys.internal_tablesAS itab
77
+
INNER JOINsys.columnsAS col
78
+
ONitab.object_id=col.object_id
79
+
INNER JOINsys.typesAS typ
80
+
ONtyp.user_type_id=col.user_type_id
81
+
ORDER BYitab.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.nameAS internal_table_name,
89
+
idx.*
90
+
FROMsys.internal_tablesAS itab
91
+
INNER JOINsys.indexesAS idx
92
+
ONitab.object_id=idx.object_id
93
+
ORDER BYitab.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.nameAS internal_table_name,
101
+
s.*
102
+
FROMsys.internal_tablesAS itab
103
+
INNER JOINsys.statsAS s
104
+
ONitab.object_id=s.object_id
105
+
ORDER BYitab.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.nameAS internal_table_name,
113
+
idx.nameAS heap_or_index_name,
114
+
p.*,
115
+
au.*
116
+
FROMsys.internal_tablesAS itab
117
+
INNER JOINsys.indexesAS idx
118
+
-- JOIN to the heap or the clustered index
119
+
ONitab.object_id=idx.object_id
120
+
ANDidx.index_idIN (0, 1)
121
+
INNER JOINsys.partitionsAS p
122
+
ONp.object_id=idx.object_id
123
+
ANDp.index_id=idx.index_id
124
+
INNER JOINsys.allocation_unitsAS 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
+
ONau.container_id= CASE au.type WHEN 2 THEN p.partition_id ELSE p.hobt_id END
128
+
ORDER BYitab.name, idx.index_id;
129
+
```
130
+
131
+
### G. Return internal table metadata for XML indexes
132
+
133
+
```sql
134
+
SELECTt.nameAS parent_table,
135
+
t.object_idAS parent_table_id,
136
+
it.nameAS internal_table_name,
137
+
it.object_idAS internal_table_id,
138
+
xi.nameAS primary_XML_index_name,
139
+
xi.index_idAS primary_XML_index_id
140
+
FROMsys.internal_tablesAS it
141
+
INNER JOINsys.tablesAS t
142
+
ONit.parent_id=t.object_id
143
+
INNER JOINsys.xml_indexesAS xi
144
+
ONit.parent_id=xi.object_id
145
+
ANDit.parent_minor_id=xi.index_id
146
+
WHEREit.internal_type_desc='XML_INDEX_NODES';
147
+
GO
148
+
```
149
+
150
+
### H. Return internal table metadata for Service Broker queues
151
+
152
+
```sql
153
+
SELECTq.nameAS queue_name,
154
+
q.object_idAS queue_id,
155
+
it.nameAS internal_table_name,
156
+
it.object_idAS internal_table_id
157
+
FROMsys.internal_tablesAS it
158
+
INNER JOINsys.service_queuesAS q
159
+
ONit.parent_id=q.object_id
160
+
WHEREit.internal_type_desc='QUEUE_MESSAGES';
161
+
GO
162
+
```
163
+
164
+
## I. Return internal table metadata for all Service Broker services
0 commit comments