SQL Server object_id () function

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.