Nishant Rana
Nishant Rana

Reputation: 13

Is there any difference between OBJECT_ID('TEMPDB..#t1') and OBJECT_ID(N'TEMPDB..#t1')

We can check if #t1 exists using OBJECT_ID('TEMPDB..#t1').

But I have also seen OBJECT_ID(N'TEMPDB..#t1') many times.

I have searched for that but didn't get any answer.Is there any real difference between them?

If there is any difference then which one to use?

Upvotes: 0

Views: 421

Answers (3)

Pedram
Pedram

Reputation: 6508

First of all, In OBJECT_ID(N'TEMPDB..#t1') -

"N" is used to specify a unicode string.

Second thing, both the syntax will work, but it depends on your requirement.

PS: N' means - sending unicode charcters.

Upvotes: 1

shA.t
shA.t

Reputation: 16968

Syntax is:

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

Arguments

  • ' object_name '

    Is the object to be used. object_name is either varchar or nvarchar. If object_name is varchar, it is implicitly converted to nvarchar. Specifying the database and schema names is optional.

  • ' object_type '

    Is the schema-scoped object type. object_type is either varchar or nvarchar. If object_type is varchar, it is implicitly converted to nvarchar. For a list of object types, see the type column in sys.objects (Transact-SQL).

Using N will represent a string as nvarchar.

Upvotes: 1

Joe Taras
Joe Taras

Reputation: 15389

The first: OBJECT_ID('TEMPDB..#t1') use varchar notation, the second: OBJECT_ID(N'TEMPDB..#t1') use nvarchar notation.

But the behaviour is the same

Upvotes: 0

Related Questions