What is N ???

  • Hi all

    Ive been working with SQL for many years and I keep coming across a syntax for strings that Ive never seen a good explanation of.  I have searched for the answer a bit but haven't found much.

    What is N for when it prefixes a string  such as N'string'

    I read somewhere that it might have to do with unicode but I personally have never used it.

     

    thanks

  • "to do with unicode" is correct. Just as the delimeter characters for a char, varchar, or text type literal are ' and ' (or " and "), the delimeter characters for a nchar, nvarchar, or ntext literal are N' and ' (or N" and ").

    I can't think of another T-SQL syntax example where more than one delimeter character is used, but in theory delimters could be whatever a language designer wanted.

  • The N before the quotes says that the text inside the quotes should be treated as unicode.

    If you ever start working with something funky like Japanese text in your database, you'll learn pretty quick that you can't get japanese text into the database and back out the same unless you use the N'unicode text' you will be able to see the unicode data in enterprise manager.

    It won't make much difference for normal english text, asides from taking up twice the space.


    Julian Kuiters
    juliankuiters.id.au

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

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