http://huihai.iteye.com/blog/1005144
In a stored procedure, there are often
SQL code
- SET quoted_identifier on
- SET quoted_identifier off
SET quoted_identifier OnSET quoted_identifier off
Such a statement, then SET QUOTED_IDENTIFIER what exactly mean, what is the use of it, this afternoon carefully looked at.
If SET QUOTED_IDENTIFIER on, when creating a table, the table name of the table is exactly the SQL Server identifier, as in the following scenario
SQL code
- Create Table distinct (
- ID int not null constraint pk_1 primary key,
- Value varchar (255),
- Flag int
- )
CREATE TABLE distinct (ID int not NULL constraint Pk_1 primary key, value varchar (255), flag int)
The above statement will run in error, regardless of whether set QUOTED_IDENTIFIER is on or off, it will prompt for syntax errors near the keyword ' distinct '.
That's because distinct is an identifier for SQL Server, and if you want to distinct as a table, you can't create a table with a table named distinct when QUOTED_IDENTIFIER is off, because in Quoted_ IDENTIFIER is off, SQL Server's identifier is not quoted, so in the case of SET quoted_identifier off, it is not possible to enclose the distinct in quotation marks or without quotation marks or double quotes.
However, in the case of SET QUOTED_IDENTIFIER on, the SQL Server identifier can be enclosed in double quotation marks to create a table with the SQL Server identifier as the table name, but it is also not possible to add single quotes.
SQL code
- Create table "distinct" (
- ID int not null constraint pk_1 primary key,
- Value varchar (255),
- Flag int
- )
CREATE TABLE "distinct" (id int not NULL constraint Pk_1 primary key, value varchar (255), flag int)
Can run
SQL code
- Create table 'distinct ' (
- ID int not null constraint pk_1 primary key,
- Value varchar (255),
- Flag int
- )
CREATE TABLE ' distinct ' (id int not NULL constraint Pk_1 primary key, value varchar (255), flag int)
Can not run
QUOTED_IDENTIFIER ON/off in SQL stored procedures