Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

SCHEMA_ID (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 ID associated with a schema name.

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_ID ( [ schema_name ] ) 

Term

Definition

schema_name

Is the name of the schema. schema_name is a sysname. If schema_name is not specified, SCHEMA_ID will return the ID of the default schema of the caller.

int

NULL will be returned if schema_name is not a valid schema.

SCHEMA_ID will return IDs of system schemas and user-defined schemas. SCHEMA_ID can be called in a select list, in a WHERE clause, and anywhere an expression is allowed.

A. Returning the default schema ID of a caller

SELECT SCHEMA_ID();
GO

B. Returning the schema ID of a named schema

USE AdventureWorks2012;
GO
SELECT SCHEMA_ID('HumanResources');
GO 

Community Additions

ADD
Show:
© 2015 Microsoft