Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does N and U stand for and what are its meaning while finding an object

Tags:

sql-server

IF OBJECT_ID (N'dbo.AWBuildVersion', N'U') IS NOT NULL
DROP TABLE dbo.AWBuildVersion;

I don't understand what N and U are for in SQL server ?

Thanks

like image 459
Bpoon Avatar asked Nov 16 '14 15:11

Bpoon


2 Answers

  • U stands for Table (user-defined). Check here for more info. The syntax OBJECT_ID is

    OBJECT_ID ( '[ database_name . [ schema_name ] . | schema_name . ] 
    object_name' [ ,'object_type' ] )
    

    here Object_type = 'U' which denotes Table (user-defined)

  • N Makes the String to be considered as nvarchar data type. It denotes that the subsequent string is in Unicode (the N actually stands for National language character set). Which means that you are passing an NCHAR, NVARCHAR or NTEXT value, as opposed to CHAR, VARCHAR or TEXT.
like image 113
Pரதீப் Avatar answered Sep 19 '22 16:09

Pரதீப்


'U' character stands for itself. The N prefix makes it a one-character UNICODE string. OBJECT_ID procedure expects you to pass one of pre-defined one-character values for the second parameter, which needs to be a UNICODE string.

This syntax is used to create literals with characters in other encodings, for example

CREATE TABLE hello_world (str NVARCHAR(20))
INSERT INTO hello_world (str) VALUES (N'Здравствуй, мир!')
like image 22
Sergey Kalinichenko Avatar answered Sep 19 '22 16:09

Sergey Kalinichenko