Программирование >>  Понятие sql 

1 ... 78 79 80 [ 81 ] 82 83 84 ... 95


Глава 19

CREATE INDEX Mydate ON Orders(snum, odate);

CREATE UNIQUE INDEX Combination ON Customers(snum, rating);

Глава 18

CREATE TABLE Orders

(onum integer NOT NULL PRIMARY KEY,

amt decimal,

odate date NOT NULL,

cnum integer NOT NULL, snum integer NOT NULL, UNIOUE (snum, cnum));

CREATE TABLE Orders

(onum integer NOT NULL UNIQUE, amt decimal, odate date NOT NULL, cnum integer NOT NULL, snum integer NOT NULL, UNIQUE (snum, cnum));

Первое решение предпочтительнее.

CREATE TABLE Salespeople

(snum integer NOT NULL PRIMARY KEY,

sname char(15) CHECK (sname BETWEEN AA AND MZ), city char(15),

comm decimal NOT NULL DEFAULT = .10);

CREATE TABLE Orders

(onum integer NOT NULL, amt decimal, odate date,

cnum integer NOT NULL, snum integer NOT NULL,

CHECK ((cnum > snum) AND (onum > cnum)));



CREATE TABLE Cityorders

(onum integer NOT NULL PRIMARY KEY,

amt decimal, cnum integer, snum integer, city char (15),

FOREIGN KEY (onum, amt, snum) REFERENCES Orders (onum, amt, snum),

FOREIGN KEY (cnum, city) REFERENCES Customers (cnum, city));

CREATE TABLE Orders

(onum integer NOT NULL, amt decimal, odate date,

cnum integer NOT NULL, snum integer, prev integer, UNIQUE (cnum, onum),

FOREIGN KEY (cnum, prev) REFERENCES Orders (cnum,onum));

Глава 20

CREATE VIEW Highratings AS SELECT *

FROM Customers

WHERE rating = (SELECT MAX (rating) FROM Customers);

CREATE VIEW Citynumber

AS SELECT city, COUNT (DISTINCT snum)

FROM Salespeople

GROUP BY city;

CREATE VIEW Nameorders

AS SELECT sname, AVG (amt), SUM (amt)

FROM Salespeople, Orders

WHERE Salespeople.snum = Orders.snum

GROUP BY sname;

CREATE VIEW Multcustomers AS SELECT *

FROM Salespeople a WHERE 1 < (SELECT COUNT (*) FROM Customers b WHERE a.snum = b.snum);

Глава 21



#1 - не модифицируемый, потому что он использует DISTINCT. #2 - не модифицируемый, потому что он использует обьединение, агрегатную функцию и GROUP BY.

#3 - не модифицируемый, потому что он основывается на #1, который сам по себе не модифицируемый.

CREATE VIEW Commissions AS SELECT snum, comm FROM Salespeople

WHERE comm BETWEEN .10 AND .20

WITH CHECK OPTION;

CREATE TABLE Orders

(onum integer NOT NULL PRIMARY KEY, amt decimal,

odate date DEFAULT VALUE = CURDATE, snum integer, cnum integer);

CREATE VIEW Entryorders AS SELECT onum, amt, snum, cnum FROM Orders;

Глава 22

GRANT UPDATE (rating) ON Customers TO Janet;

GRANT SELECT ON Orders TO Stephen WITH GRANT OPTION;

REVOKE INSERT ON Salespeople FROM Claire;

Шаг 1:

CREATE VIEW Jerrysview

AS SELECT *

FROM Customers

WHERE rating BETWEEN 100 AND 500 WITH CHECK OPTION;

Шаг 2:

GRANT INSERT, UPDATE ON Jerrysview TO Jerry;

Шаг 1:



1 ... 78 79 80 [ 81 ] 82 83 84 ... 95

© 2006 - 2024 pmbk.ru. Генерация страницы: 0
При копировании материалов приветствуются ссылки.
Яндекс.Метрика