Export (0) Print
Expand All

SCHEMA_NAME (Transact-SQL)

Applies To: SQL Server 2014, SQL Server 2016 Preview

Topic Status: Some information in this topic is preview and subject to change in future releases. Preview information describes new features or changes to existing features in Microsoft SQL Server 2016 Community Technology Preview 2 (CTP2).

Returns the schema name associated with a schema ID.

Applies to: SQL Server (SQL Server 2008 through current version), Azure SQL Database, Azure SQL Data Warehouse Public Preview.

Topic link icon Transact-SQL Syntax Conventions

SCHEMA_NAME ( [ schema_id ] )

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.

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
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2015 Microsoft