object_id () function

SQLServer database, if there is a query whether the specified name database index or foreign key constraints, often used object_id ( 'name', 'type ') method, taking notes as follows:

?

语法:object_id('objectname')或object('objectname','type')

Action: This function returns the value of the specified object ID may be verified sysobjects table.

Wherein objectname datatype char or nchar. If the  object  's data type is char, then convert it to a recessive nchar.

type the following list:

V = View
U = Table (user-defined)
P = SQL Stored Procedure


AF = Aggregate function (CLR)
C = CHECK constraint
D = DEFAULT (constraint or stand-alone)
F = FOREIGN KEY constraint
FN = SQL scalar function
FS = Assembly (CLR) scalar-function
FT = Assembly (CLR) table-valued function
IF = SQL inline table-valued function
IT = Internal table
PC = Assembly (CLR) stored-procedure
PG = Plan guide
PK = PRIMARY KEY constraint
R = Rule (old-style, stand-alone)
RF = Replication-filter-procedure
S = System base table
SN = Synonym
SQ = Service queue
TA = Assembly (CLR) DML trigger
TF = SQL table-valued-function
TR = SQL DML trigger
UQ = UNIQUE constraint
X = Extended stored procedure

Examples are as follows:

select object_id ( 'fk_xxx_xx', 'F') will remove the constraint ID value called fk_xxx_xx, as the return value 144,444,444.

This is equivalent to:

select ID from sysobjects where name='fk_xxx_xx' and type='F'

======================================================================================= 

We all know that there is a system sysobjects table in the database, which stores information about each object in the database. Query results can take a look at. Can be seen that each object has an ID, the table stores tables, stored procedures, triggers, views, and other related information. Note: Field no.

  object_id is to return the id of the object by object name.
  object_name is the name of the object based on the object id return.
 

  select object_id (object name) is equivalent to:
  SELECT ID from the sysobjects WHERE name = object name

  select object_name (id number) is equivalent to:
  SELECT name from the sysobjects WHERE ID = ID number

======================================================================================= 

Judgment temporary table

if object_id(N'tempdb..#ABC',N'U') is  null

tempdb is an important part of the SQL Server database system has been SQLServer used to store temporary objects. Can be simply understood tempdb is SQLServer sketch plate. Application and database tempdb can be used as a temporary data storage area. All users share a single instance of a Tempdb.

Guess you like

Origin www.cnblogs.com/kuangwong/p/11346542.html