
Scope and Impact of Metadata Visibility Configuration
Metadata visibility configuration only applies to the following securables.
|
Catalog views
|
Database Engine sp_help stored procedures
|
|
Metadata exposing built-in functions
|
Information schema views
|
|
Compatibility views
|
Extended properties
|
Metadata visibility configuration does not apply to the following securables.
|
Log shipping system tables
|
SQL Server Agent system tables
|
|
Database maintenance plan system tables
|
Backup system tables
|
|
Replication system tables
|
Replication and SQL Server Agent sp_help stored procedures
|
Limited metadata accessibility means the following:
-
Applications that assume public metadata access will break.
-
Queries on system views might only return a subset of rows, or sometimes an empty result set.
-
Metadata-emitting, built-in functions such as OBJECTPROPERTYEX may return NULL.
-
The Database Engine sp_help stored procedures might return only a subset of rows, or NULL.
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 SQL Server, a row is returned.
CREATE PROCEDURE assumes_caller_can_access_metadata
BEGIN
SELECT name, id
FROM sysobjects
WHERE name = 'myTable';
END;
GO
To allow callers to view metadata, you can grant the callers VIEW DEFINITION permission at an appropriate scope: object level, database level or server level. Therefore, in the previous example, if the caller has VIEW DEFINITION permission on myTable, the stored procedure returns a row. For more information, see GRANT (Transact-SQL) and GRANT Database Permissions (Transact-SQL).
You can also modify the stored procedure so that it executes under the credentials of the owner. When the procedure owner and the table owner are the same owner, ownership chaining applies, and the security context of the procedure owner enables access to the metadata for myTable. Under this scenario, the following code returns a row of metadata to the caller.
CREATE PROCEDURE does_not_assume_caller_can_access_metadata
WITH EXECUTE AS OWNER
AS
BEGIN
SELECT name, id
FROM sys.objects
WHERE name = 'myTable'
END;
GO
Note: |
|---|
|
You can use EXECUTE AS to temporarily switch to the security context of the caller. For more information, see EXECUTE AS (Transact-SQL).
|
For more information about ownership chaining, see Ownership Chains.