看看例子吧:
A. Use the quoted identifier setting and reserved word object names
This example shows that the SET QUOTED_IDENTIFIER setting must be ON, and the keywords in table names must be in double quotation s to create and use objects with reserved keyword names.SET QUOTED_IDENTIFIER OFF
GO
-- Attempt to create a table with a reserved keyword as a name
-- should fail.
CREATE TABLE "select" ("identity" int IDENTITY, "order" int)
GOSET QUOTED_IDENTIFIER ON
GO-- Will succeed.
CREATE TABLE "select" ("identity" int IDENTITY, "order" int)
GOSELECT "identity","order" 
FROM "select"
ORDER BY "order"
GODROP TABLE "SELECT"
GOSET QUOTED_IDENTIFIER OFF
GOB. Use the quoted identifier setting with single and double quotes
This example shows the way single and double quotation s are used in string expressions with SET QUOTED_IDENTIFIER set to ON and OFF.SET QUOTED_IDENTIFIER OFF
GO
USE pubs
IF EXISTS(SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS
      WHERE TABLE_NAME = 'Test')
   DROP TABLE Test
GO
USE pubs
CREATE TABLE Test ( Id int, String varchar (30) ) 
GO-- Literal strings can be in single or double quotation s.
INSERT INTO Test VALUES (1,"'Text in single quotes'")
INSERT INTO Test VALUES (2,'''Text in single quotes''')
INSERT INTO Test VALUES (3,'Text with 2 '''' single quotes')
INSERT INTO Test VALUES (4,'"Text in double quotes"')
INSERT INTO Test VALUES (5,"""Text in double quotes""")
INSERT INTO Test VALUES (6,"Text with 2 """" double quotes")
GOSET QUOTED_IDENTIFIER ON
GO-- Strings inside double quotation s are now treated 
-- as object names, so they cannot be used for literals.
INSERT INTO "Test" VALUES (7,'Text with a single '' quote')
GO-- Object identifiers do not have to be in double quotation s
-- if they are not reserved keywords.
SELECT * 
FROM Test
GODROP TABLE Test
GOSET QUOTED_IDENTIFIER OFF
GOHere is the result set:Id          String                         
----------- ------------------------------ 
1           'Text in single quotes'        
2           'Text in single quotes'        
3           Text with 2 '' single quotes   
4           "Text in double quotes"        
5           "Text in double quotes"        
6           Text with 2 "" double quotes   
7           Text with a single ' quote     

解决方案 »

  1.   

    当 SET QUOTED_IDENTIFIER 为 ON 时,由双引号分隔的所有字符串都被解释为对象标识符。因此,加引号的标识符不必遵守 Transact-SQL 标识符规则。它们可以是保留关键字,并且可以包含 Transact-SQL 标识符中通常不允许的字符。不能使用双引号分隔文字字符串表达式,而必须用单引号括住文字字符串。如果单引号 (') 是文字字符串的一部分,则可以由两个单引号 ('') 表示。当对数据库中的对象名使用保留关键字时,SET QUOTED_IDENTIFIER 必须为 ON。当 SET QUOTED_IDENTIFIER 为 OFF(默认值)时,表达式中的文字字符串可以由单引号或双引号分隔。如果文字字符串由双引号分隔,则可以在字符串中包含嵌入式单引号,如省略号。