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

3

3 Answers 3

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.

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).

0

Q1: Object_id and OBJECT_ID are one and the same.

Q2 is already answered [here][1]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.