• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1725
  • Last Modified:

What does the N' mean in the code "object_id(N'[Northwind].[dbo].[Categories2]') "?

I got the code below from this site:

Can someone tell me what does the N' mean and what relationship does it has with "[Northwind].[dbo].[Categories2] code  next to it in the WHERE statement (second line) of the code below?

IF EXISTS (SELECT * from sysobjects
   WHERE id = object_id(N'[Northwind].[dbo].[Categories2]') AND
   OBJECTPROPERTY(id, N'IsUserTable') = 1)
   DROP Table [Northwind].[dbo].[Categories2]

THe FireBird thanks you.

  • 3
2 Solutions
N' means Unicode characters coding.
To proper function In case when names have characters outside ASCII
from BOL

Unicode strings

Unicode strings have a format similar to character strings but are preceded by an N identifier (N stands for National Language in the SQL-92 standard). The N prefix must be uppercase. For example, 'Michél' is a character constant while N'Michél' is a Unicode constant. Unicode constants are interpreted as Unicode data, and are not evaluated using a code page. Unicode constants do have a collation, which primarily controls comparisons and case sensitivity. Unicode constants are assigned the default collation of the current database, unless the COLLATE clause is used to specify a collation. Unicode data is stored using two bytes per character, as opposed to one byte per character for character data
BirdsOfFire1Author Commented:
To: mokule

I have MS Server SQL 8.0, which I assume is not the SQL-92 standard.   Will just "object_id([Northwind].[dbo].[Categories2]) work?  I took out the N' in the statement above.

When should I use the N' in the object_id?  

The Firebird

You must use it when there are characters in the string having code outside ASCII

N'  is used when we require to convert a particular string to a NVARCHAR format....
you can do without N if your function does not require that you explicitly pass a Nvarchar.

For some system procedures or function is is required that you pass a Nvarchar and not a VArchar

Execute sp_executesql N'select * from dtproperties'
this statement would work fine but
Execute sp_executesql 'select * from dtproperties'
this statement would give you an error

Hope this helps


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now