What is mean N'123456'?

  • What is mean N'123456 in code below?

    Select * from order where orderID=N'123456'

  • The N denotes the N(VAR)CHAR type, without it the N it would be (VAR)Char.

    😎

  • It also means that unless the OrderID column is NVARCHAR, the code isn't SARGable (can't do an INDEX SEEK) and will cause a table scan to do an implicit conversion of all OrderIDs in the table to NVARCHAR because of the high order that NVARCHAR has for data precedence. This is very typical of ORM code and the database normally gets the blame instead of the ORM.

    --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)

  • Some users uploaded Access tables to SQL are always NVARCHAR type.

    I found that nvarchar cause performace problem. Is it true?

  • adonetok (3/26/2014)


    Some users uploaded Access tables to SQL are always NVARCHAR type.

    I found that nvarchar cause performace problem. Is it true?

    I don't know why anyone that knew anything about table structure would store what is typically a "digits only" column as NVARCHAR or even VARCHAR. It not only makes for performance problems but causes "row bloat" (a performance, storage, backup, restore, and index problem to name just a few). If real numeric sorts are important, storing such "digit only" data really puts the screws to performance there. The users have made a terrible mistake by doing this themselves instead of working with the DBA on this.

    As a side bar, this is why I don't allow users to have anything but read privs (sometimes, write but never DDL privs) in production. They just don't know what they don't know.

    --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)

  • They just don't know what they don't know.

    Thats a million dollar quote, Jeff

    Bravooo !!!! :hehe:

  • twin.devil (3/26/2014)


    They just don't know what they don't know.

    Thats a million dollar quote, Jeff

    Bravooo !!!! :hehe:

    You can only achieve wisdom if you know what you don't know. 😉

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

Viewing 7 posts - 1 through 6 (of 6 total)

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