0

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

Hare Rama Hare Krishna
  • 1,025
  • 5
  • 14
  • 19
  • 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

1

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
  • 732,580
  • 175
  • 1,330
  • 1,459
Jean-François Savard
  • 20,626
  • 7
  • 49
  • 76
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
  • 380,855
  • 102
  • 628
  • 825
0

Q1: Object_id and OBJECT_ID are one and the same.

Q2 is already answered [here][1]

variable
  • 8,262
  • 9
  • 95
  • 215