Skip to content

Latest commit

 

History

History
70 lines (52 loc) · 2.38 KB

File metadata and controls

70 lines (52 loc) · 2.38 KB
title SCHEMA_NAME (Transact-SQL)
description SCHEMA_NAME (Transact-SQL)
author MikeRayMSFT
ms.author mikeray
ms.date 03/03/2017
ms.service sql
ms.subservice t-sql
ms.topic reference
f1_keywords
SCHEMA_NAME
SCHEMA_NAME_TSQL
helpviewer_keywords
SCHEMA_NAME function
schemas [SQL Server], names
dev_langs
TSQL
monikerRange >= aps-pdw-2016 || = azuresqldb-current || = azure-sqldw-latest || >= sql-server-2016 || >= sql-server-linux-2017 || = azuresqldb-mi-current||=fabric

SCHEMA_NAME (Transact-SQL)

[!INCLUDE sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw]

Returns the schema name associated with a schema ID.

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-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();  

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

SELECT SCHEMA_NAME(1);  

See Also

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