object_id
Returns the database object identification number of the schema-scoped object.
Important Notes
Objects that are not schema-scoped (such as DDL triggers) cannot be queried using OBJECT_ID. For objects that are not found in the Sys.objects catalog view, you need to get the object's identification number by querying the appropriate catalog view. For example, to return the object identification number of a DDL trigger, use the SELECT object_id from sys.triggers WHERE name = ' Databasetriggerlog ' syntax:
OBJECT_ID (' [database_name. [Schema_name]. | Schema_name. ] object_name ' [, ' object_type '])
Parameters:
The object to be used by ' object_name '. The data type of the object_name is varchar or nvarchar. If the object_name data type is varchar, it is implicitly converted to nvarchar. You can choose whether to specify a database and schema name.
The object type of the ' object_type ' schema scope. The data type of the object_type is varchar or nvarchar. If the object_type data type is varchar, it is implicitly converted to nvarchar. For a list of object types, see the Type column in sys.objects (Transact-SQL).
return type:int
Example:
A. Returning the object ID of the specified object
Use master; Goselect object_id (N ' AdventureWorks.Production.WorkOrder ') as ' OBJECT ID '; GO
B. Verifying that an object exists
Use AdventureWorks; GOif object_id (N ' dbo. Awbuildversion ', N ' U ') is not nulldrop TABLE dbo. Awbuildversion; GO
SQL Server object_id () function