看看例子吧:
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
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
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货