Jun 22

OBJECT_ID() en #sqlserver

Es una de las funciones mas utilizadas y nos permite prevenir errores como en  TRY .. CATCH.

Aunque tiene otro usos, nosotros lo vamos a utilizar principalmente para ver la existencia de objetos.

Captura

Podemos comprobar:

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

Nos puede ser muy util a la hora de crear procedimientos almcenados, funciones, etc….