I have encountered the following code in the book "TSQL Fundamentals" by Itzik Ben-Gan.
I understand that the function OBJECT_ID is used to check whether a particular object exists or not. However I'm a bit confused by its second argument N'U'.
I looked up MSDN documentation and it says that the second argument represents the object type, but I still dont understand what N'U' stands for.
Could someone please explain it to me what it actually represents?
IF OBJECT_ID(N'dbo.Employees', N'U') IS NOT NULL
BEGIN
IF OBJECTPROPERTY(OBJECT_ID(N'dbo.Employees', N'U'), N'TableTemporalType') = 2
ALTER TABLE dbo.Employees SET(SYSTEM_VERSIONING = OFF);
If you follow the link in the page you linked to types: sys.objects
U = Table (user-defined)
**Complete list (as of 2017-01-16)**
Object type:
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
P = SQL Stored Procedure
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
SO = Sequence object
Applies to: SQL Server 2012 through SQL Server 2016.
SQ = Service queue
TA = Assembly (CLR) DML trigger
TF = SQL table-valued-function
TR = SQL DML trigger
TT = Table type
U = Table (user-defined)
UQ = UNIQUE constraint
V = View
X = Extended stored procedure
Applies to: SQL Server 2016 through SQL Server 2016, Azure SQL
Database, Azure SQL Data Warehouse, Parallel Data Warehouse.
ET = External Table
SELECT DISTINCT type,type_desc FROM sys.objects
type type_desc ---- ------------------------------------------------------------ TT TYPE_TABLE FN SQL_SCALAR_FUNCTION SN SYNONYM IF SQL_INLINE_TABLE_VALUED_FUNCTION UQ UNIQUE_CONSTRAINT SQ SERVICE_QUEUE F FOREIGN_KEY_CONSTRAINT U USER_TABLE D DEFAULT_CONSTRAINT PK PRIMARY_KEY_CONSTRAINT V VIEW S SYSTEM_TABLE IT INTERNAL_TABLE P SQL_STORED_PROCEDURE TF SQL_TABLE_VALUED_FUNCTION
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With