Question Regarding N in SQL Statement

  • I have a silly question I was wondering if someone can help me understand. I have the following SQL Statement that I saw :

    IF EXISTS(SELECT * FROM sys.objects

    WHERE object_id = OBJECT_ID(N'[dbo].[Orders]') AND type in (N'U'))

    PRINT 'Exists!'

    ELSE

    PRINT 'Don''t Exists'

    When I run this code it works. Can someone tell me what is the N for within the line N'[dbo].[Orders]. If I take out the N in both places the code still runs successfully. So, what is the purpose? or is there a purpose?

  • N is used before character data literals to specify that it is a unicode string (nvarchar, nchar data types). SQL Server will normally do an implicit conversion of non-unicode strings to unicode, but there is a slight performance hit when this occurs.

  • Thanks for the explanation.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply