OBJECT_SCHEMA_NAME()
Returns the database schema name for schema-scoped objects. For a list of schema-scoped objects, see sys.objects (Transact-SQL).
Signature
OBJECT_SCHEMA_NAME ( object_id [, database_id ] )Parameters
- object_id — The ID of the object to be used. *object_id* is int and is assumed to be a schema-scoped object in the specified database, or in the current database context.
- database_id — The ID of the database where the object is to be looked up. *database_id* is int.
Examples
SELECT DISTINCT OBJECT_SCHEMA_NAME(object_id)
FROM master.sys.objects;NULL
sysSELECT DISTINCT OBJECT_SCHEMA_NAME(object_id, 1) AS schema_name
FROM master.sys.objects;dbo
sysRun against SQL Server 16.0.4265.3 on 2026-09-13. This is the output we got, not the documentation’s.
Available on
- SQL Server 2017 and later
- Azure SQL Database
- Azure SQL Managed Instance
- Azure Synapse Analytics
- Azure SQL Edge
- Microsoft Fabric warehouse
- Fabric SQL database
Signature and description adapted from the Microsoft SQL documentation, used under the CC BY 4.0. SQL Server and Azure are trademarks of the Microsoft group of companies. This page is not affiliated with Microsoft.