Object_ID and Object_Name functions – SQL Server

Object_id() and Object_name() functions are used to get the schema-scoped object’s Identification number and Name.

Object_id(): This function is used to get the schema-scoped object identification number in a database object. this function returns an integer value.

Function usage:

OBJECT_ID ( object_name, [object_type ] )

We can provide object name with database name and schema name. For instance, TestDb.dbo.Object_name or dbo.Object_name. Object type parameter is also an optional value. But, if you want to use this value then you can use the information given in below image.

Implementation

Object_name: This function gives the object name for schema-scoped objects in a database. It returns a sysname (nvarchar(128) NOT NULL) type output.

Function Usage

OBJECT_NAME ( object_id [, database_id ] )

We have to provide the object identification number to this function to get the object name. Database identification number is an optional parameter.

Implementation

1. Get object name

2. Fetch values from the table using object id.

Catalog Views

We can use these catalog views to fetch the object information with more details

1) List user-defined, schema-scoped objects
Select * from sys.objects

2) List of all schema-scoped system objects
select * from sys.system_objects

3) UNION of all schema-scoped user-defined objects and system objects.
select * from sys.all_objects