Search code examples
sql-servert-sqlansi-sqlansi-sql-92

Is N'some string here' ANSI SQL?


We know that in order to qualify a string literal as Unicode, we need to prefix it with N in Transact-SQL. My question is if this is part any standard such as ANSI SQL. Will other database platforms understand this?

UPDATE:

My practical experiments with Mig# show that in order to work with Unicode literals:


Solution

  • According to the MSDN documentation for constants in T-SQL, the N' prefix is part of the "SQL-92" standard:

    Unicode strings have a format similar to character strings but are preceded by an N identifier (N stands for National Language in the SQL-92 standard).

    According to Wikipedia, "National Character" strings were added in that version of the standard. That article references what appears to be the actual standard document http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt wherein it says:

    The <key word>s NATIONAL CHARACTER are used to specify a character string data type with a particular implementation-defined character repertoire. Special syntax (N'string') is provided for representing literals in that character repertoire.

    So, yes, it seems that it is definitely part of the standard.

    UPDATE:

    As Damien_The_Unbeliever pointed out in the comments here, the above-linked standard document is actually a draft (and supposedly the actual standard document is not publicly available), but in my opinion, there seems to be sufficient evidence that, at least inasmuch as the national character N is concerned, that is the standard.