Results 1 to 7 of 7

Thread: SQL Syntax N'

  1. #1
    Join Date
    Nov 2006
    Posts
    6

    SQL Syntax N'

    Some SQL examples enclose string within N' ...' , what does it mean?

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    That is using National Character Set. This is required if you are using sp_executesql

  3. #3
    Join Date
    Nov 2006
    Posts
    6
    What is the purpose of using N''? I removed N from the quoted string, query executed without problem generating the same result.
    Thanks

  4. #4
    Join Date
    Sep 2005
    Posts
    168
    Try using different characters than Latin ones without the N'' prefix, then select from your table and you will see the difference in how data are stored in the tables.
    No matter if you specify the N'' for a string or not, the code will always execute without errors.

    The following lines are from BOL:
    One problem with data types that use 1 byte to encode each character is that the data type can only represent 256 different characters. This forces multiple encoding specifications (or code pages) for different alphabets such as European alphabets, which are relatively small. It is also impossible to handle systems such as the Japanese Kanji or Korean Hangul alphabets that have thousands of characters.

    Each Microsoft® SQL Server™ collation has a code page that defines what patterns of bits represent each character in char, varchar, and text values. Individual columns and character constants can be assigned a different code page. Client computers use the code page associated with the operating system locale to interpret character bit patterns. There are many different code pages. Some characters appear on some code pages, but not on others. Some characters are defined with one bit pattern on some code pages, and with a different bit pattern on other code pages. When you build international systems that must handle different languages, it becomes difficult to pick code pages for all the computers that meet the language requirements of multiple countries. It is also difficult to ensure that every computer performs the correct translations when interfacing with a system using a different code page.

    The Unicode specification addresses this problem by using 2 bytes to encode each character. There are enough different patterns (65,536) in 2 bytes for a single specification covering the most common business languages. Because all Unicode systems consistently use the same bit patterns to represent all characters, there is no problem with characters being converted incorrectly when moving from one system to another. You can minimize character conversion issues by using Unicode data types throughout your system.

    In Microsoft SQL Server, these data types support Unicode data:
    nchar
    nvarchar
    ntext

    Note The n prefix for these data types comes from the SQL-92 standard for National (Unicode) data types.

    Use of nchar, nvarchar, and ntext is the same as char, varchar, and text, respectively, except that:

    Unicode supports a wider range of characters.

    More space is needed to store Unicode characters.

    The maximum size of nchar and nvarchar columns is 4,000 characters, not 8,000 characters like char and varchar.

    Unicode constants are specified with a leading N: N'A Unicode string'.

    All Unicode data uses the same Unicode code page. Collations do not control the code page used for Unicode columns, only attributes such as comparison rules and case sensitivity.

    --HTH--

  5. #5
    Join Date
    Nov 2006
    Posts
    6
    thanks Mikros.
    If i am sure Unicode data would not be stored in my production database, eliminating N' in all queries is not a problem right?

  6. #6
    Join Date
    Sep 2005
    Posts
    168
    Probably there will not be any problem
    --HTH--

  7. #7
    Join Date
    Sep 2002
    Posts
    5,938
    You don't need N if you don't use unicode column.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •