0

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?

3 Answers3

1

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.

shA.t
  • 16,580
  • 5
  • 54
  • 111
1

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.

Pedram
  • 6,256
  • 10
  • 65
  • 87
0

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

Joe Taras
  • 15,166
  • 7
  • 42
  • 55