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
description: Contains information about the query and its associated overall aggregated runtime execution statistics.
4
4
author: rwestMSFT
5
5
ms.author: randolphwest
6
-
ms.date: 12/16/2023
6
+
ms.date: 07/14/2025
7
7
ms.service: sql
8
8
ms.subservice: system-objects
9
9
ms.topic: "reference"
@@ -28,9 +28,9 @@ Contains information about the query and its associated overall aggregated runti
28
28
| Column name | Data type | Description |
29
29
| --- | --- | --- |
30
30
|`query_id`|**bigint**| Primary key. |
31
-
|`query_text_id`|**bigint**| Foreign key. Joins to [sys.query_store_query_text (Transact-SQL)](sys-query-store-query-text-transact-sql.md)|
32
-
|`context_settings_id` <sup>1</sup> |**bigint**| Foreign key. Joins to [sys.query_context_settings (Transact-SQL)](sys-query-context-settings-transact-sql.md). |
33
-
|`object_id` <sup>2</sup> |**bigint**| ID of the database object that the query is part of (stored procedure, trigger, CLR UDF/UDAgg, etc.). `0` if the query isn't executed as part of a database object (ad hoc query). |
31
+
|`query_text_id`|**bigint**| Foreign key. Joins to [sys.query_store_query_text](sys-query-store-query-text-transact-sql.md)|
32
+
|`context_settings_id` <sup>1</sup> |**bigint**| Foreign key. Joins to [sys.query_context_settings](sys-query-context-settings-transact-sql.md). |
33
+
|`object_id` <sup>2</sup> |**bigint**| ID of the database object that the query is part of (stored procedure, trigger, CLR UDF/UDAgg, etc.). `0` if the query isn't executed as part of a database object (ad hoc query). See the [Remarks](#remarks) section in this article. |
34
34
|`batch_sql_handle` <sup>3</sup> |**varbinary(64)**| ID of the statement batch the query is part of. Populated only if query references temporary tables or table variables. |
35
35
|`query_hash`|**binary(8)**| Zobrist hash over the shape of the individual query, based on the bound (input) logical query tree. Query hints aren't included as part of the hash. |
36
36
|`is_internal_query` <sup>2</sup> |**bit**| The query was generated internally. |
@@ -39,7 +39,7 @@ Contains information about the query and its associated overall aggregated runti
|`last_compile_start_time`|**datetimeoffset**| Most recent compile start time. |
41
41
|`last_execution_time`|**datetimeoffset**| Last execution time refers to the last end time of the query/plan. |
42
-
|`last_compile_batch_sql_handle`|**varbinary(64)**| Handle of the last SQL batch in which query was used last time. It can be provided as input to [sys.dm_exec_sql_text (Transact-SQL)](../system-dynamic-management-views/sys-dm-exec-sql-text-transact-sql.md) to get the full text of the batch. |
42
+
|`last_compile_batch_sql_handle`|**varbinary(64)**| Handle of the last SQL batch in which query was used last time. It can be provided as input to [sys.dm_exec_sql_text](../system-dynamic-management-views/sys-dm-exec-sql-text-transact-sql.md) to get the full text of the batch. |
43
43
|`last_compile_batch_offset_start` <sup>2</sup> |**bigint**| Information that can be provided to `sys.dm_exec_sql_text` along with `last_compile_batch_sql_handle`. |
44
44
|`last_compile_batch_offset_end` <sup>2</sup> |**bigint**| Information that can be provided to `sys.dm_exec_sql_text` along with `last_compile_batch_sql_handle`. |
The `object_id` column is populated only when the statement is compiled from a Transact‑SQL module. A module is any schema‑scoped object that has a row in [sys.sql_modules](sys-sql-modules-transact-sql.md).
72
+
73
+
Because the query optimizer expands non-indexed views before it produces a plan, only the underlying tables remain, though indexed views do appear as tables.
Returns a row for each object that is a SQL language-defined module in [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)], including natively compiled scalar user-defined function. Objects of type P, RF, V, TR, FN, IF, TF, and R have an associated SQL module. Stand-alone defaults, objects of type D, also have a SQL module definition in this view. For a description of these types, see the `type` column in the [sys.objects](../../relational-databases/system-catalog-views/sys-objects-transact-sql.md) catalog view.
25
-
26
-
For more information, see [Scalar User-Defined Functions for In-Memory OLTP](../../relational-databases/in-memory-oltp/scalar-user-defined-functions-for-in-memory-oltp.md).
|**object_id**|**int**|ID of the object of the containing object. Is unique within a database.|
31
-
|**definition**|**nvarchar(max)**|SQL text that defines this module. This value can also be obtained using the [OBJECT_DEFINITION](../../t-sql/functions/object-definition-transact-sql.md) built-in function.<br /><br /> NULL = Encrypted.|
32
-
|**uses_ansi_nulls**|**bit**|Module was created with SET ANSI_NULLS ON.<br /><br /> Will always be = 0 for rules and defaults.|
33
-
|**uses_quoted_identifier**|**bit**|Module was created with SET QUOTED_IDENTIFIER ON.|
34
-
|**is_schema_bound**|**bit**|Module was created with SCHEMABINDING option.<br /><br /> Always contains a value of 1 for natively compiled stored procedures.|
35
-
|**uses_database_collation**|**bit**|1 = Schema-bound module definition depends on the default-collation of the database for correct evaluation; otherwise, 0. Such a dependency prevents changing the database's default collation.|
36
-
|**is_recompiled**|**bit**|Procedure was created WITH RECOMPILE option.|
37
-
|**null_on_null_input**|**bit**|Module was declared to produce a `NULL` output on any `NULL` input.|
38
-
|**execute_as_principal_id**|**Int**|ID of the EXECUTE AS database principal.<br /><br /> `NULL` by default or if EXECUTE AS CALLER.<br /><br /> ID of the specified principal if EXECUTE AS SELF or EXECUTE AS \<principal>.<br /><br /> -2 = EXECUTE AS OWNER.|
39
-
|**uses_native_compilation**|**bit**|**Applies to**: [!INCLUDE[ssSQL14](../../includes/sssql14-md.md)] through [!INCLUDE[ssSQL14](../../includes/sssql14-md.md)].<br /><br /> 0 = not natively compiled<br /><br /> 1 = is natively compiled<br /><br /> The default value is 0.|
40
-
|**is_inlineable**|**bit**|**Applies to**: [!INCLUDE[sssql19-md](../../includes/sssql19-md.md)] and later.<br/><br />Indicates whether the module is inlineable or not. Inlineability is based on the conditions specified [here](../user-defined-functions/scalar-udf-inlining.md#requirements).<br /><br /> 0 = not inlineable<br /><br /> 1 = is inlineable. <br /><br /> For scalar user-defined functions (UDFs), the value will be 1 if the UDF is inlineable, and 0 otherwise. It always contains a value of 1 for inline table-valued functions (TVFs), and 0 for all other module types.<br />|
41
-
|**inline_type**|**bit**|**Applies to**: [!INCLUDE[sssql19-md](../../includes/sssql19-md.md)] and later.<br /><br />Indicates whether inlining is turned on for the module currently. <br /><br />0 = inlining is turned off<br /><br /> 1 = inlining is turned on.<br /><br /> For scalar user-defined functions (UDFs), the value will be 1 if inlining is turned on (explicitly or implicitly). The value will always be 1 for inline table-valued functions (TVFs), and 0 for other module types.<br />|
25
+
Returns a row for each object that is a SQL language-defined module in [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)], including natively compiled scalar user-defined function. Objects of type `P`, `RF`, `V`, `TR`, `FN`, `IF`, `TF`, and `R` have an associated SQL module. Stand-alone defaults, objects of type `D`, also have a SQL module definition in this view. For a description of these types, see the `type` column in the [sys.objects](sys-objects-transact-sql.md) catalog view.
26
+
27
+
For more information, see [Scalar User-Defined Functions for In-Memory OLTP](../in-memory-oltp/scalar-user-defined-functions-for-in-memory-oltp.md).
28
+
29
+
| Column name | Data type | Description |
30
+
| --- | --- | --- |
31
+
|`object_id`|**int**| ID of the object of the containing object. Is unique within a database. |
32
+
|`definition`|**nvarchar(max)**| SQL text that defines this module. This value can also be obtained using the [OBJECT_DEFINITION](../../t-sql/functions/object-definition-transact-sql.md) built-in function.<br /><br />`NULL` = Encrypted. |
33
+
|`uses_ansi_nulls`|**bit**| Module was created with `SET ANSI_NULLS ON`.<br /><br />Always `0` for rules and defaults. |
34
+
|`uses_quoted_identifier`|**bit**| Module was created with `SET QUOTED_IDENTIFIER ON`. |
35
+
|`is_schema_bound`|**bit**| Module was created with `SCHEMABINDING` option.<br /><br />Always contains a value of `1` for natively compiled stored procedures. |
36
+
|`uses_database_collation`|**bit**|`1` = Schema-bound module definition depends on the default-collation of the database for correct evaluation; otherwise, `0`. Such a dependency prevents changing the database's default collation. |
37
+
|`is_recompiled`|**bit**| Procedure was created `WITH RECOMPILE` option. |
38
+
|`null_on_null_input`|**bit**| Module was declared to produce a `NULL` output on any `NULL` input. |
39
+
|`execute_as_principal_id`|**Int**| ID of the `EXECUTE AS` database principal.<br /><br />`NULL` by default or if `EXECUTE AS CALLER`.<br />ID of the specified principal if `EXECUTE AS SELF` or `EXECUTE AS <principal>`.<br />`-2` = `EXECUTE AS OWNER`. |
40
+
|`uses_native_compilation`|**bit**|`0` = not natively compiled<br />`1` = is natively compiled<br /><br />The default value is `0`.<br /><br /> **Applies to**: [!INCLUDE [ssSQL14](../../includes/sssql14-md.md)] and later versions. |
41
+
|`is_inlineable`|**bit**| Indicates whether the module can be inlined or not. Inlineability is based on the conditions specified in the [requirements](../user-defined-functions/scalar-udf-inlining.md#requirements).<br /><br />`0` = can't be inlined<br />`1` = can be inlined.<br /><br />For scalar user-defined functions (UDFs), the value is `1` if the UDF can be inlined, and `0` otherwise. It always contains a value of `1` for inline table-valued functions (TVFs), and `0` for all other module types.<br /><br />**Applies to**: [!INCLUDE [sssql19-md](../../includes/sssql19-md.md)] and later versions. |
42
+
|`inline_type`|**bit**| Indicates whether inlining is turned on for the module currently.<br />0 = inlining is turned off<br />1 = inlining is turned on.<br />For scalar user-defined functions (UDFs), the value is `1` if inlining is turned on (explicitly or implicitly). The value is always `1` for inline table-valued functions (TVFs), and `0` for other module types.<br /><br />**Applies to**: [!INCLUDE [sssql19-md](../../includes/sssql19-md.md)] and later versions. |
43
+
44
+
## Remarks
45
+
46
+
The SQL expression for a `DEFAULT` constraint, object of type `D`, is found in the [sys.default_constraints](sys-default-constraints-transact-sql.md) catalog view. The SQL expression for a `CHECK` constraint, object of type `C`, is found in the [sys.check_constraints](sys-check-constraints-transact-sql.md) catalog view.
47
+
48
+
This information is also described in [sys.dm_db_uncontained_entities](../system-dynamic-management-views/sys-dm-db-uncontained-entities-transact-sql.md).
49
+
50
+
Renaming a stored procedure, function, view, or trigger doesn't change the name of the corresponding object in the definition column of the `sys.sql_modules` catalog view or the definition returned by the [OBJECT_DEFINITION](../../t-sql/functions/object-definition-transact-sql.md) built-in function. For this reason, we recommend that you don't use `sp_rename` to rename these object types. Instead, drop and recreate the object with its new name. Learn more in [sp_rename](../system-stored-procedures/sp-rename-transact-sql.md).
51
+
52
+
## Permissions
53
+
54
+
[!INCLUDE [ssCatViewPerm](../../includes/sscatviewperm-md.md)] For more information, see [Metadata Visibility Configuration](../security/metadata-visibility-configuration.md).
55
+
56
+
## Examples
57
+
58
+
The following example returns the object_id, schema name, object name, object type, and definition of each module in the current database.
59
+
60
+
```sql
61
+
SELECTsm.object_id,
62
+
ss.[name] AS [schema],
63
+
o.[name] AS object_name,
64
+
o.[type],
65
+
o.[type_desc],
66
+
sm.[definition]
67
+
FROMsys.sql_modulesAS sm
68
+
INNER JOINsys.objectsAS o
69
+
ONsm.object_id=o.object_id
70
+
INNER JOINsys.schemasAS ss
71
+
ONo.schema_id=ss.schema_id
72
+
ORDER BY o.[type], ss.[name], o.[name];
73
+
```
74
+
75
+
## Related content
42
76
43
-
44
-
## Remarks
45
-
The SQL expression for a DEFAULT constraint, object of type D, is found in the [sys.default_constraints](../../relational-databases/system-catalog-views/sys-default-constraints-transact-sql.md) catalog view. The SQL expression for a CHECK constraint, object of type C, is found in the [sys.check_constraints](../../relational-databases/system-catalog-views/sys-check-constraints-transact-sql.md) catalog view.
46
-
47
-
This information is also described in [sys.dm_db_uncontained_entities (Transact-SQL)](../../relational-databases/system-dynamic-management-views/sys-dm-db-uncontained-entities-transact-sql.md).
48
-
49
-
Renaming a stored procedure, function, view, or trigger won't change the name of the corresponding object in the definition column of the `sys.sql_modules` catalog view or the definition returned by the [OBJECT_DEFINITION](../../t-sql/functions/object-definition-transact-sql.md) built-in function. For this reason, we recommend that `sp_rename` not be used to rename these object types. Instead, drop and re-create the object with its new name. Learn more in [sp_rename (Transact-SQL)](../../relational-databases/system-stored-procedures/sp-rename-transact-sql.md).
50
-
51
-
## Permissions
52
-
[!INCLUDE[ssCatViewPerm](../../includes/sscatviewperm-md.md)] For more information, see [Metadata Visibility Configuration](../../relational-databases/security/metadata-visibility-configuration.md).
53
-
54
-
## Examples
55
-
The following example returns the object_id, schema name, object name, object type, and definition of each module in the current database.
0 commit comments