The letter N?

  • Can someone tell me why the letter N is used to prefix certain TSQL statements?  For example,

    BACKUP DATABASE [msdb] TO  DISK = N'C:\Program Files\Microsoft SQL Server\....’

    OR

    IF EXISTS(SELECT name FROM sysobjects WHERE  name = N'test_table' AND type = 'U') DROP TABLE test_table

    These statements work fine without the N being used as a prefix but EM and QA always include the N.  Why?

    Thanks in advance.

    Eddie

  • It's used to identify UNICODE and is used with NCHAR and NVARCHAR.

    Look in BOL under NCHAR and NVARCHAR.

    -SQLBill

  • Cool, thanks for letting me know.  And thanks for telling me where to find it in BOL.

    Eddie

  • Ok, according to BOL:

    ------------------------------------------------------------------------------------

    Unicode Data

    Traditional non-Unicode data types in Microsoft® SQL Server™ 2000 allow the use of characters that are defined by a particular character set. A character set is chosen during SQL Server Setup and cannot be changed. Using Unicode data types, a column can store any character defined by the Unicode Standard, which includes all of the characters defined in the various character sets. Unicode data types take twice as much storage space as non-Unicode data types.

    Unicode data is stored using the nchar, nvarchar, and ntext data types in SQL Server. Use these data types for columns that store characters from more than one character set. Use nvarchar when a column's entries vary in the number of Unicode characters (up to 4,000) they contain. Use nchar when every entry for a column has the same fixed length (up to 4,000 Unicode characters). Use ntext when any entry for a column is longer than 4,000 Unicode characters.

    Note The SQL Server Unicode data types are based on the National Character data types in the SQL-92 standard. SQL-92 uses the prefix character n to identify these data types and values.

    ------------------------------------------------------------------------------------

    Does this necessarily mean that if I know my application(s) are only going to be used in the US, and won't ever need any other locale, I should save the space and continue using non-Unicode data types (char, varchar, text)?

  • >Does this necessarily mean that if I know my application(s) are only going to be used in the US, and won't ever need any other locale, I should save the space and continue using non-Unicode data types (char, varchar, text)?

    I'd certainly think so...

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 5 posts - 1 through 4 (of 4 total)

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