SQL Server/T-SQL/System/QUOTED IDENTIFIER

Материал из SQL эксперт
Перейти к: навигация, поиск

Cannot create index. Object "myView" was created with the following SET options off: "QUOTED_IDENTIFIER"

1> create table employee(
2>     ID          int,
3>     name        nvarchar (10),
4>     salary      int,
5>     start_date  datetime,
6>     city        nvarchar (10),
7>     region      char (1))
8> GO
1>
2> insert into employee (ID, name,    salary, start_date, city,       region)
3>               values (1,  "Jason", 40420,  "02/01/94", "New York", "W")
4> GO
(1 rows affected)
1> insert into employee (ID, name,    salary, start_date, city,       region)
2>               values (2,  "Robert",14420,  "01/02/95", "Vancouver","N")
3> GO
(1 rows affected)
1> insert into employee (ID, name,    salary, start_date, city,       region)
2>               values (3,  "Celia", 24020,  "12/03/96", "Toronto",  "W")
3> GO
(1 rows affected)
1> insert into employee (ID, name,    salary, start_date, city,       region)
2>               values (4,  "Linda", 40620,  "11/04/97", "New York", "N")
3> GO
(1 rows affected)
1> insert into employee (ID, name,    salary, start_date, city,       region)
2>               values (5,  "David", 80026,  "10/05/98", "Vancouver","W")
3> GO
(1 rows affected)
1> insert into employee (ID, name,    salary, start_date, city,       region)
2>               values (6,  "James", 70060,  "09/06/99", "Toronto",  "N")
3> GO
(1 rows affected)
1> insert into employee (ID, name,    salary, start_date, city,       region)
2>               values (7,  "Alison",90620,  "08/07/00", "New York", "W")
3> GO
(1 rows affected)
1> insert into employee (ID, name,    salary, start_date, city,       region)
2>               values (8,  "Chris", 26020,  "07/08/01", "Vancouver","N")
3> GO
(1 rows affected)
1> insert into employee (ID, name,    salary, start_date, city,       region)
2>               values (9,  "Mary",  60020,  "06/09/02", "Toronto",  "W")
3> GO
(1 rows affected)
1>
2> select * from employee
3> GO
ID          name       salary      start_date              city       region
----------- ---------- ----------- ----------------------- ---------- ------
          1 Jason            40420 1994-02-01 00:00:00.000 New York   W
          2 Robert           14420 1995-01-02 00:00:00.000 Vancouver  N
          3 Celia            24020 1996-12-03 00:00:00.000 Toronto    W
          4 Linda            40620 1997-11-04 00:00:00.000 New York   N
          5 David            80026 1998-10-05 00:00:00.000 Vancouver  W
          6 James            70060 1999-09-06 00:00:00.000 Toronto    N
          7 Alison           90620 2000-08-07 00:00:00.000 New York   W
          8 Chris            26020 2001-07-08 00:00:00.000 Vancouver  N
          9 Mary             60020 2002-06-09 00:00:00.000 Toronto    W
(9 rows affected)
1>
2> -- Indexed Views
3>
4> CREATE VIEW myView
5> WITH SchemaBinding
6> As
7> SELECT ID, Name FROM dbo.Employee
8> GO
1> -- A unique clustered index is created on the view.
2>
3> CREATE UNIQUE CLUSTERED INDEX CL_MyView
4> ON MyView (ID)
5> GO
Msg 1935, Level 16, State 1, Server sqle\SQLEXPRESS, Line 3
Cannot create index. Object "myView" was created with the following SET options off: "QUOTED_IDENTIFIER".
1>
2> select * from myview
3> GO
ID          Name
----------- ----------
          1 Jason
          2 Robert
          3 Celia
          4 Linda
          5 David
          6 James
          7 Alison
          8 Chris
          9 Mary
(9 rows affected)
1> drop table employee
2> GO
Msg 3729, Level 16, State 1, Server sqle\SQLEXPRESS, Line 1
Cannot DROP TABLE "employee" because it is being referenced by object "myView".
1>



SET QUOTED_IDENTIFIER ON/OFF

 

2>
3> CREATE TABLE employee(
4>    id          INTEGER NOT NULL PRIMARY KEY,
5>    first_name  VARCHAR(10),
6>    last_name   VARCHAR(10),
7>    salary      DECIMAL(10,2),
8>    start_Date  DATETIME,
9>    region      VARCHAR(10),
10>    city        VARCHAR(20),
11>    managerid   INTEGER
12> );
13> GO
1> INSERT INTO employee VALUES (1, "Jason" ,  "Martin", 5890,"2005-03-22","North","Vancouver",3);
2> GO
(1 rows affected)
1> INSERT INTO employee VALUES (2, "Alison",  "Mathews",4789,"2003-07-21","South","Utown",4);
2> GO
(1 rows affected)
1> INSERT INTO employee VALUES (3, "James" ,  "Smith",  6678,"2001-12-01","North","Paris",5);
2> GO
(1 rows affected)
1> INSERT INTO employee VALUES (4, "Celia" ,  "Rice",   5567,"2006-03-03","South","London",6);
2> GO
(1 rows affected)
1> INSERT INTO employee VALUES (5, "Robert",  "Black",  4467,"2004-07-02","East","Newton",7);
2> GO
(1 rows affected)
1> INSERT INTO employee VALUES (6, "Linda" ,  "Green" , 6456,"2002-05-19","East","Calgary",8);
2> GO
(1 rows affected)
1> INSERT INTO employee VALUES (7, "David" ,  "Larry",  5345,"2008-03-18","West","New York",9);
2> GO
(1 rows affected)
1> INSERT INTO employee VALUES (8, "James" ,  "Cat",    4234,"2007-07-17","West","Regina",9);
2> GO
(1 rows affected)
1> INSERT INTO employee VALUES (9, "Joan"  ,  "Act",    6123,"2001-04-16","North","Toronto",10);
2> GO
(1 rows affected)
1>
2> select * from employee;
3> GO
id          first_name last_name  salary       start_Date              region     city                 managerid
----------- ---------- ---------- ------------ ----------------------- ---------- -------------------- -----------
          1 Jason      Martin          5890.00 2005-03-22 00:00:00.000 North      Vancouver                      3
          2 Alison     Mathews         4789.00 2003-07-21 00:00:00.000 South      Utown                          4
          3 James      Smith           6678.00 2001-12-01 00:00:00.000 North      Paris                          5
          4 Celia      Rice            5567.00 2006-03-03 00:00:00.000 South      London                         6
          5 Robert     Black           4467.00 2004-07-02 00:00:00.000 East       Newton                         7
          6 Linda      Green           6456.00 2002-05-19 00:00:00.000 East       Calgary                        8
          7 David      Larry           5345.00 2008-03-18 00:00:00.000 West       New York                       9
          8 James      Cat             4234.00 2007-07-17 00:00:00.000 West       Regina                         9
          9 Joan       Act             6123.00 2001-04-16 00:00:00.000 North      Toronto                       10
(9 rows affected)
1>
2>
3> SET QUOTED_IDENTIFIER OFF
4> GO
1>
2> BEGIN TRAN Restore_Value
3> DECLARE @ValueToUpdate VARCHAR(30)
4> SET @ValueToUpdate = "Blankets"
5> UPDATE Employee
6>    SET First_name = @ValueToUpdate
7> COMMIT TRAN
8>
9> SET QUOTED_IDENTIFIER ON
10> GO
(9 rows affected)
1>
2>
3> SELECT * FROM Employee
4> GO
id          first_name last_name  salary       start_Date              region     city                 managerid
----------- ---------- ---------- ------------ ----------------------- ---------- -------------------- -----------
          1 Blankets   Martin          5890.00 2005-03-22 00:00:00.000 North      Vancouver                      3
          2 Blankets   Mathews         4789.00 2003-07-21 00:00:00.000 South      Utown                          4
          3 Blankets   Smith           6678.00 2001-12-01 00:00:00.000 North      Paris                          5
          4 Blankets   Rice            5567.00 2006-03-03 00:00:00.000 South      London                         6
          5 Blankets   Black           4467.00 2004-07-02 00:00:00.000 East       Newton                         7
          6 Blankets   Green           6456.00 2002-05-19 00:00:00.000 East       Calgary                        8
          7 Blankets   Larry           5345.00 2008-03-18 00:00:00.000 West       New York                       9
          8 Blankets   Cat             4234.00 2007-07-17 00:00:00.000 West       Regina                         9
          9 Blankets   Act             6123.00 2001-04-16 00:00:00.000 North      Toronto                       10
(9 rows affected)
1>
2>
3>
4> drop table employee;
5> GO