-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZooDatabase.sql
85 lines (61 loc) · 2.33 KB
/
ZooDatabase.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
-- Drop all the tables to clean up
DROP TABLE Handles;
DROP TABLE Animal;
DROP TABLE ZooKeeper;
CREATE TABLE ZooKeeper
(
ZID NUMBER(3,0),
ZName VARCHAR2(25) NOT NULL,
HourlyRate NUMBER(6, 2) NOT NULL,
CONSTRAINT ZooKeeper_PK
PRIMARY KEY(ZID)
);
-- ACategory: Animal category 'common', 'rare', 'exotic'. May be NULL
-- TimeToFeed: Time it takes to feed the animal (hours)
CREATE TABLE Animal
(
AID NUMBER(3, 0),
AName VARCHAR(30) NOT NULL,
ACategory VARCHAR(18),
TimeToFeed NUMBER(4,2),
CONSTRAINT Animal_PK
PRIMARY KEY(AID)
);
CREATE TABLE Handles
(
ZooKeepID NUMBER(3,0),
AnimalID NUMBER(3,0),
Assigned DATE,
CONSTRAINT Handles_PK
PRIMARY KEY(ZooKeepID, AnimalID),
CONSTRAINT Handles_FK1
FOREIGN KEY(ZooKeepID)
REFERENCES ZooKeeper(ZID),
CONSTRAINT Handles_FK2
FOREIGN KEY(AnimalID)
REFERENCES Animal(AID)
);
INSERT INTO ZooKeeper VALUES (1, 'Jim Carrey', 500);
INSERT INTO ZooKeeper VALUES (2, 'Tina Fey', 350);
INSERT INTO ZooKeeper VALUES (3, 'Rob Schneider', 250);
INSERT INTO Animal VALUES(1, 'Galapagos Penguin', 'exotic', 0.5);
INSERT INTO Animal VALUES(2, 'Emperor Penguin', 'rare', 0.75);
INSERT INTO Animal VALUES(3, 'Sri Lankan sloth bear', 'exotic', 2.5);
INSERT INTO Animal VALUES(4, 'Grizzly bear', 'common', 3.0);
INSERT INTO Animal VALUES(5, 'Giant Panda bear', 'exotic', 1.5);
INSERT INTO Animal VALUES(6, 'Florida black bear', 'rare', 1.75);
INSERT INTO Animal VALUES(7, 'Siberian tiger', 'rare', 3.5);
INSERT INTO Animal VALUES(8, 'Bengal tiger', 'common', 2.75);
INSERT INTO Animal VALUES(9, 'South China tiger', 'exotic', 2.25);
INSERT INTO Animal VALUES(10, 'Alpaca', 'common', 0.25);
INSERT INTO Animal VALUES(11, 'Llama', NULL, 3.5);
INSERT INTO Handles VALUES(1, 1, '01-Jan-2000');
INSERT INTO Handles VALUES(1, 2, '02-Jan-2000');
INSERT INTO Handles VALUES(1, 10, '01-Jan-2000');
INSERT INTO Handles VALUES(2, 3, '02-Jan-2000');
INSERT INTO Handles VALUES(2, 4, '04-Jan-2000');
INSERT INTO Handles VALUES(2, 5, '03-Jan-2000');
INSERT INTO Handles VALUES(3, 7, '01-Jan-2000');
INSERT INTO Handles VALUES(3, 8, '03-Jan-2000');
INSERT INTO Handles VALUES(3, 9, '05-Jan-2000');
INSERT INTO Handles Values(3, 10,'04-Jan-2000');