TechNet
Export (0) Print
Expand All

SCHEMA_NAME (Transact-SQL)

 

THIS TOPIC APPLIES TO: yesSQL Server (starting with 2008)yesAzure SQL DatabaseyesAzure SQL Data Warehouse yesParallel Data Warehouse

Returns the schema name associated with a schema ID.

Topic link icon Transact-SQL Syntax Conventions

  
SCHEMA_NAME ( [ schema_id ] )  

-- Azure SQL Data Warehouse and Parallel Data Warehouse  
SCHEMA_NAME ( [ schema_id ] )  

TermDefinition
schema_idThe 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.

sysname

Returns NULL when schema_id is not a valid ID.

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.

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 AdventureWorks2012;  
GO  
SELECT SCHEMA_NAME(5);  
GO  

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

SELECT SCHEMA_NAME();  

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

SELECT SCHEMA_NAME(1);  

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

Community Additions

ADD
Show:
© 2016 Microsoft