What is the use of putting N' before any query?

  • Hello,

    I'm not sure about the use of putting 'N' before any query.

    For eg -

    Backup Database AdventureWorks to

    Disk = N'C:\adv_test1.bak',

    Disk = N'D:\adv_test1.bak',

    with no format, noinit

    Name = N'Adventure works-Full database backup',

    skip, norewind, nounload, stats = 10

    Please suggest.

    Rgds,
    Pankaj

  • By prefixing a constant string with "N", you are letting SQL to know that the string is a UNICODE string.

    --Ramesh


  • Thanks for the reply Ramesh, However, i know it is for SQL to understand that it's gonna be a Unicode value....

    that's my question actually that.... why do we need to pass a unicode value.... when do we actually need it..? what would happen if I'll not pass a unicode value ..... bottom line is .... what is the advantage of it?

    Rgds,
    Pankaj

  • Hi

    I would say it depends.

    In maintenance scripts I think it is a "best practice", SSE does the conversion and the overhead should be okay.

    In procedures and functions you should use an explicit Unicode string if your values are Unicode. If you don't specify the N'' SSE has to convert your constant text with every call of the compiled module.

    Greets

    Flo

  • pankaj.baluni (5/19/2009)


    .... why do we need to pass a unicode value

    When the calling procedure expects a UNICODE value

    pankaj.baluni (5/19/2009)


    when do we actually need it..?

    To support international language support

    pankaj.baluni (5/19/2009)


    .... what would happen if I'll not pass a unicode value

    SQL Server will try to convert the non-unicode value to a unicode value and thereby adding additional overhead on SQL Engine.

    pankaj.baluni (5/19/2009)


    ..... bottom line is .... what is the advantage of it?

    Support for international languages

    --Ramesh


  • Thank you very much Ramesh,

    That answers all my questions.... 😛

    Rgds,
    Pankaj

  • You are welcome..

    --Ramesh


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

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