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
SQL modules, such as stored procedures and triggers, run under the security context of the caller and, therefore, have limited metadata accessibility. For example, in the following code, when the stored procedure tries to access metadata for the table `myTable` on which the caller has no rights, an empty result set is returned. In earlier releases of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)], a row is returned.
> The following example uses the [sys.objects](../../relational-databases/system-catalog-views/sys-objects-transact-sql.md) catalog view instead of the [sys.sysobjects](../../relational-databases/system-compatibility-views/sys-sysobjects-transact-sql.md) compatibility view.
The following metadata is not subject to forced disclosure:
127
126
128
-
- The value stored in the **provider_string** column of **sys.servers**. A user that does not have ALTER ANY LINKED SERVER permission will see a NULL value in this column.
127
+
- The value stored in the `provider_string` column of `sys.servers`. A user that does not have ALTER ANY LINKED SERVER permission will see a NULL value in this column.
129
128
130
129
- Source definition of a user-defined object such as a stored procedure or trigger. The source code is visible only when one of the following is true:
131
130
@@ -135,17 +134,17 @@ GO
135
134
136
135
- The definition columns found in the following catalog views:
137
136
138
-
-**sys.all_sql_modules**
139
-
-**sys.server_sql_modules**
140
-
-**sys.default_constraints**
141
-
-**sys.numbered_procedures**
142
-
-**sys.sql_modules**
143
-
-**sys.check_constraints**
144
-
-**sys.computed_columns**
137
+
-`sys.all_sql_modules`
138
+
-`sys.server_sql_modules`
139
+
-`sys.default_constraints`
140
+
-`sys.numbered_procedures`
141
+
-`sys.sql_modules`
142
+
-`sys.check_constraints`
143
+
-`sys.computed_columns`
145
144
146
-
- The **ctext** column in the **syscomments** compatibility view.
145
+
- The `ctext` column in the `syscomments` compatibility view.
147
146
148
-
- The output of the **sp_helptext** procedure.
147
+
- The output of the `sp_helptext` procedure.
149
148
150
149
- The following columns in the information schema views:
151
150
@@ -158,10 +157,13 @@ GO
158
157
159
158
- OBJECT_DEFINITION() function
160
159
161
-
- The value stored in the password_hash column of **sys.sql_logins**. A user that does not have CONTROL SERVER permission will see a NULL value in this column.
160
+
- The value stored in the password_hash column of `sys.sql_logins`. A user that does not have CONTROL SERVER permission will see a NULL value in this column.
162
161
163
162
> [!NOTE]
164
-
> The SQL definitions of built-in system procedures and functions are publicly visible through the **sys.system_sql_modules** catalog view, the **sp_helptext** stored procedure, and the OBJECT_DEFINITION() function.
163
+
> The SQL definitions of built-in system procedures and functions are publicly visible through the `sys.system_sql_modules` catalog view, the `sp_helptext` stored procedure, and the OBJECT_DEFINITION() function.
164
+
165
+
> [!NOTE]
166
+
> The system stored procedure `sp_helptext` is not supported in Azure Synapse Analytics. Instead, use the `OBJECT_DEFINITION` system function or `sys.sql_modules` object catalog view.
165
167
166
168
## General Principles of Metadata Visibility
167
169
The following are some general principles to consider regarding metadata visibility:
@@ -194,11 +196,12 @@ GO
194
196
The visibility of subcomponents, such as indexes, check constraints, and triggers is determined by permissions on the parent. These subcomponents do not have grantable permissions. For example, if a user has been granted some permission on a table, the user can view the metadata for the tables, columns, indexes, check constraints, triggers, and other such subcomponents. Another example is granting SELECT on only an individual column of a given table: this will allow the grantee to view the matadata of the whole table, including all columns. One way to think of it, is that the VIEW DEFINITION permission only works on entity-level (the table in this case) and is not available for Sub-entity lists (such as column or security expressions).
Copy file name to clipboardExpand all lines: docs/relational-databases/stored-procedures/view-the-definition-of-a-stored-procedure.md
+19-14Lines changed: 19 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
---
2
-
title: "View the Definition of a Stored Procedure | Microsoft Docs"
2
+
title: "View the Definition of a Stored Procedure"
3
3
description: Learn how to view the definition of procedure in Object Explorer and by using a system stored procedure, system function, and object catalog view in the Query Editor.
@@ -41,6 +40,9 @@ This topic describes how to view the definition of procedure in Object Explorer
41
40
42
41
Object Catalog View: **sys.sql_modules**
43
42
The visibility of the metadata in catalog views is limited to securables that a user either owns or on which the user has been granted some permission. For more information, see [Metadata Visibility Configuration](../../relational-databases/security/metadata-visibility-configuration.md).
43
+
44
+
> [!NOTE]
45
+
> The system stored procedure `sp_helptext` is not supported in Azure Synapse Analytics. Instead, use `OBJECT_DEFINITION` system function or `sys.sql_modules` object catalog view. Samples are provided later in this article.
44
46
45
47
## <aname="Procedures"></a> How to View the Definition of a Stored Procedure
46
48
You can use one of the following:
@@ -61,47 +63,50 @@ This topic describes how to view the definition of procedure in Object Explorer
61
63
4. Select **New Query Editor Window**. This will display the procedure definition.
62
64
63
65
### <aname="TsqlProcedure"></a> Using Transact-SQL
64
-
**To view the definition of a procedure in Query Editor**
66
+
67
+
#### To view the definition of a procedure in Query Editor
65
68
66
69
System Stored Procedure: **sp_helptext**
67
70
1. In Object Explorer, connect to an instance of the [!INCLUDE[ssDE](../../includes/ssde-md.md)].
68
71
69
72
2. On the toolbar, click **New Query**.
70
73
71
-
3. In the query window, enter the following statement that uses the **sp_helptext** system stored procedure. Change the database name and stored procedure name to reference the database and stored procedure that you want.
74
+
3. In the query window, enter the following statement that uses the `sp_helptext` system stored procedure. Change the database name and stored procedure name to reference the database and stored procedure that you want.
1. In Object Explorer, connect to an instance of the [!INCLUDE[ssDE](../../includes/ssde-md.md)].
81
85
82
86
2. On the toolbar, click **New Query**.
83
87
84
-
3. In the query window, enter the following statements that use the **OBJECT_DEFINITION** system function. Change the database name and stored procedure name to reference the database and stored procedure that you want.
88
+
3. In the query window, enter the following statements that use the `OBJECT_DEFINITION` system function. Change the database name and stored procedure name to reference the database and stored procedure that you want.
1. In Object Explorer, connect to an instance of the [!INCLUDE[ssDE](../../includes/ssde-md.md)].
94
99
95
100
2. On the toolbar, click **New Query**.
96
101
97
-
3. In the query window, enter the following statements that use the **sys.sql_modules** catalog view. Change the database name and stored procedure name to reference the database and stored procedure that you want.
102
+
3. In the query window, enter the following statements that use the `sys.sql_modules` catalog view. Change the database name and stored procedure name to reference the database and stored procedure that you want.
98
103
99
-
```
104
+
```sql
100
105
USE AdventureWorks2012;
101
106
GO
102
-
SELECT definition
107
+
SELECT [definition]
103
108
FROM sys.sql_modules
104
-
WHERE object_id = (OBJECT_ID(N'AdventureWorks2012.dbo.uspLogError'));
109
+
WHERE object_id = (OBJECT_ID(N'dbo.uspLogError'));
sp_helptext displays the definition that is used to create an object in multiple rows. Each row contains 255 characters of the [!INCLUDE[tsql](../../includes/tsql-md.md)] definition. The definition resides in the **definition** column in the [sys.sql_modules](../../relational-databases/system-catalog-views/sys-sql-modules-transact-sql.md) catalog view.
53
+
sp_helptext displays the definition that is used to create an object in multiple rows. Each row contains 255 characters of the [!INCLUDE[tsql](../../includes/tsql-md.md)] definition. The definition resides in the `definition` column in the [sys.sql_modules](../../relational-databases/system-catalog-views/sys-sql-modules-transact-sql.md) catalog view.
54
+
55
+
> [!NOTE]
56
+
> The system stored procedure `sp_helptext` is not supported in Azure Synapse Analytics. Instead, use `OBJECT_DEFINITION` system function or `sys.sql_modules` object catalog view for equivalent results.
55
57
56
58
## Permissions
57
59
Requires membership in the **public** role. System object definitions are publicly visible. The definition of user objects is visible to the object owner or grantees that have any one of the following permissions: ALTER, CONTROL, TAKE OWNERSHIP, or VIEW DEFINITION.
The following example displays the definition of the trigger `dEmployee` in the [!INCLUDE[ssSampleDBobject](../../includes/sssampledbobject-md.md)]database.
63
65
64
-
```
66
+
```sql
65
67
USE AdventureWorks2012;
66
68
GO
67
69
EXEC sp_helptext 'HumanResources.dEmployee';
@@ -71,7 +73,7 @@ GO
71
73
### B. Displaying the definition of a computed column
72
74
The following example displays the definition of the computed column `TotalDue` on the `SalesOrderHeader` table in the [!INCLUDE[ssSampleDBobject](../../includes/sssampledbobject-md.md)] database.
SELECT OBJECT_DEFINITION (OBJECT_ID('HumanResources.vEmployee')) AS ObjectDefinition;
198
197
GO
199
198
```
200
199
201
-
```
200
+
```sql
202
201
EXEC sp_helptext 'HumanResources.vEmployee';
203
202
```
204
203
205
204
For more information, see [sys.sql_modules (Transact-SQL)](../../relational-databases/system-catalog-views/sys-sql-modules-transact-sql.md), [OBJECT_DEFINITION (Transact-SQL)](../../t-sql/functions/object-definition-transact-sql.md) and [sp_helptext (Transact-SQL)](../../relational-databases/system-stored-procedures/sp-helptext-transact-sql.md).
205
+
206
+
> [!NOTE]
207
+
> The system stored procedure `sp_helptext` is not supported in Azure Synapse Analytics. Instead, use the `OBJECT_DEFINITION` system function or`sys.sql_modules` object catalog view.
0 commit comments