Compartilhar via


SCHEMA_NAME (Transact-SQL)

Returns the schema name associated with a schema ID.

Topic link iconTransact-SQL Syntax Conventions

Syntax

SCHEMA_NAME ( [ schema_id ] )

Arguments

Term Definition

schema_id

The ID of the schema. schema_id is an int. If schema_id is not defined, SCHEMA_NAME will return the name of the default schema of the caller.

Return Types

sysname

Returns NULL when schema_id is not a valid ID.

Remarks

SCHEMA_NAME returns names of system schemas and user-defined schemas. SCHEMA_NAME can be called in a select list, in a WHERE clause, and anywhere an expression is allowed.

Examples

A. Returning the name of the default schema of the caller

SELECT SCHEMA_NAME();
GO

B. Returning the name of a schema by using an ID

USE AdventureWorks;
GO
SELECT SCHEMA_NAME(5);
GO

See Also

Reference

Expressions (Transact-SQL)
SCHEMA_ID (Transact-SQL)
sys.schemas (Transact-SQL)
sys.database_principals (Transact-SQL)
Metadata Functions (Transact-SQL)
WHERE (Transact-SQL)

Other Resources

User-Schema Separation

Help and Information

Getting SQL Server 2005 Assistance