-1

I am using sql-server 2012 and I have this query

create table t
( 
id int not null,
name varchar(10)
);


select OBJECT_NAME(object_id) as table_name,type,name as table_name,type_dec
from sys.indexes
where object_id=OBJECT_ID(N'dbo.t',N'U')

whats the difference in object_id and OBJECT_ID and what is the use of writing N''

The query returns same result: with or without N enter image description here

  • If you mark the keyword you are curious about and hit `shift+f1` you'll get the documentation for that keyword and all the answers you need. – jpw Feb 14 '15 at 19:23
  • possible duplicate of [What is the meaning of the prefix N in T-SQL statements?](http://stackoverflow.com/questions/10025032/what-is-the-meaning-of-the-prefix-n-in-t-sql-statements) – Dudi Konfino Feb 15 '15 at 06:16
  • @HareRamaHareKrishna any feedback on this ? – Jean-François Savard Feb 15 '15 at 20:27

3 Answers3

0

The N in N'xxx' means "national language", denoting a unicode string.

If you use it to store data into a VARCHAR as opposed to a NVARCHAR column, it has little use.

You can read more about it under the "Unicode strings" sub-heading on this page: Constants (Transact-SQL).

Lasse V. Karlsen
  • 366,661
  • 96
  • 610
  • 798
0

In SQL Server, the prefix N' is used to specify a nvarchar type, which stands for national character.

From the doc :

Prefix Unicode character string constants with the letter N. Without the N prefix, the string is converted to the default code page of the database. This default code page may not recognize certain characters.

In other world, it is an unicode character.

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
Jean-François Savard
  • 20,182
  • 6
  • 46
  • 71
0

Q1: Object_id and OBJECT_ID are one and the same.

Q2 is already answered [here][1]

variable
  • 6,123
  • 5
  • 52
  • 127