Syntax : object_id (' [database_name. [Schema_name]. | Schema_name. ] object_name ' [, ' object_type '])
Parameters :
-
'
object_name
'
-
The object to use. 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.
-
'
object_type
'
-
The schema-scoped object type. 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
Abnormal:
For spatial indexes, OBJECT_ID returns NULL.
When an error occurs, NULL is returned.
The user can only view the metadata of the securable object it owns, or the security object to which the permission has been granted. That is, if the user does not have any permissions on the object, some built-in functions that produce metadata, such as object_id, may return NULL. For more information, see Troubleshooting Metadata visibility configuration and metadata visibility.
Comments:
When this parameter is optional for system functions, the system takes the current database, host, server user, or database user. The built-in function must be followed by parentheses.
When you specify a temporary table name, you must precede the temporary table name with the database name unless the current database is tempdb. For example: SELECT OBJECT_ID(‘tempdb..#mytemptable‘)
.
System functions can be used in select lists, where clauses, and wherever expressions are allowed to be used. For more information, see Expressions (Transact-SQL) and WHERE (Transact-SQL).
Category: Databases
The object_id () function in SQL SERVER