-
Notifications
You must be signed in to change notification settings - Fork 0
/
theatre_0_creation.sql
196 lines (168 loc) · 5.9 KB
/
theatre_0_creation.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
-- Final: Theatre Database
-- CS345 Databases Harcourt
-- Kim, Tom, and Corinna
-- Purpose: DDL to create our database and its tables.
DROP DATABASE IF EXISTS finalproject_tom_corinna_kim;
CREATE DATABASE finalproject_tom_corinna_kim;
\c finalproject_tom_corinna_kim
-- DROP DATABASE IF EXISTS finalproject_tom_corinna_kim;
-- CREATE DATABASE finalproject_tom_corinna_kim;
-- \c finalproject_tom_corinna_kim
CREATE TABLE ShowNames (
name varchar(30) NOT NULL,
PRIMARY KEY (name));
CREATE TABLE Venue (
name varchar(30) NOT NULL,
zip_code char(5) NOT NULL,
state char(2) NOT NULL,
fee float4 NOT NULL,
seats int4 NOT NULL,
sq_ft int4 NOT NULL,
removable_seats int4 NOT NULL,
removable_floor int4 NOT NULL,
orchestra_capacity int4 NOT NULL,
PRIMARY KEY (name));
CREATE TABLE TimeSlot (
time time(6) NOT NULL,
day varchar(9) NOT NULL,
PRIMARY KEY (time, day));
CREATE TABLE ShowDates (
"date" date NOT NULL,
name varchar(30) NOT NULL,
PRIMARY KEY ("date"),
FOREIGN KEY (name) REFERENCES ShowNames (name));
CREATE TABLE Book (
show_name varchar(30) NOT NULL,
book varchar(30) NOT NULL,
instrument varchar(30) NOT NULL,
PRIMARY KEY (show_name, book, instrument),
FOREIGN KEY (show_name) REFERENCES ShowNames (name));
CREATE TABLE People (
name varchar(30) NOT NULL,
birthdate date NOT NULL,
dept varchar(30) NOT NULL,
title varchar(30) NOT NULL,
phone char(10) NOT NULL,
email varchar(30) UNIQUE,
PRIMARY KEY (name, birthdate));
CREATE TABLE Wages (
name varchar(30) NOT NULL,
birthdate date NOT NULL,
year int4 NOT NULL,
wage float4 NOT NULL,
PRIMARY KEY (name, birthdate, year),
FOREIGN KEY (name, birthdate) REFERENCES People (name, birthdate));
CREATE TABLE Hours (
show_date date NOT NULL,
name varchar(30) NOT NULL,
birthdate date NOT NULL,
hours float4 NOT NULL,
PRIMARY KEY (show_date, name, birthdate),
FOREIGN KEY (name, birthdate) REFERENCES People (name, birthdate));
CREATE TABLE Transportation (
type varchar(30) NOT NULL,
"date" date NOT NULL,
seats int4 NOT NULL,
cubic_ft float4 NOT NULL,
cost float4 NOT NULL,
PRIMARY KEY (type, "date"));
CREATE TABLE DonorTier (
type varchar(30) NOT NULL,
threshold float4 NOT NULL,
PRIMARY KEY (type));
CREATE TABLE Donors (
name varchar(30) NOT NULL,
birthdate date NOT NULL,
phone char(10) NOT NULL,
email varchar(30) NOT NULL,
PRIMARY KEY (name, birthdate));
CREATE TABLE Donations (
name varchar(30) NOT NULL,
birthdate date NOT NULL,
show_date date NOT NULL,
amount float4 NOT NULL,
anonymous boolean NOT NULL,
PRIMARY KEY (name, birthdate, show_date),
FOREIGN KEY (name, birthdate) REFERENCES Donors (name, birthdate));
CREATE TABLE Ticket (
type varchar(30) NOT NULL,
cost float4 NOT NULL,
PRIMARY KEY (type));
CREATE TABLE Company (
name varchar(30) NOT NULL,
venue_name varchar(30) NOT NULL,
type varchar(30) NOT NULL,
cost float4 NOT NULL,
PRIMARY KEY (name, venue_name),
FOREIGN KEY (venue_name) REFERENCES Venue (name));
CREATE TABLE Characters (
show_name varchar(30) NOT NULL,
character varchar(30) NOT NULL,
PRIMARY KEY (show_name, character),
FOREIGN KEY (show_name) REFERENCES ShowNames (name));
CREATE TABLE Role (
show_date date NOT NULL,
name varchar(30) NOT NULL,
birthdate date NOT NULL,
character varchar(30) NOT NULL,
PRIMARY KEY (show_date, name, birthdate, character),
FOREIGN KEY (show_date) REFERENCES ShowDates ("date"),
FOREIGN KEY (name, birthdate) REFERENCES People (name, birthdate));
CREATE TABLE ShowVenue (
"date" date NOT NULL,
name varchar(30) NOT NULL,
PRIMARY KEY ("date", name),
FOREIGN KEY ("date") REFERENCES ShowDates ("date"),
FOREIGN KEY (name) REFERENCES Venue (name));
CREATE TABLE Instruments (
instrument varchar(30) NOT NULL,
PRIMARY KEY (instrument));
CREATE TABLE Plays (
name varchar(30) NOT NULL,
birthdate date NOT NULL,
instrument varchar(30) NOT NULL,
PRIMARY KEY (name, birthdate, instrument),
FOREIGN KEY (name, birthdate) REFERENCES People (name, birthdate),
FOREIGN KEY (instrument) REFERENCES Instruments (instrument));
CREATE TABLE VenueTime (
name varchar(30) NOT NULL,
time time(6) NOT NULL,
day varchar(10) NOT NULL,
PRIMARY KEY (name, time, day),
FOREIGN KEY (name) REFERENCES Venue (name),
FOREIGN KEY (time, day) REFERENCES TimeSlot (time, day));
CREATE TABLE Understudy (
show_date date NOT NULL,
name varchar(30) NOT NULL,
birthdate date NOT NULL,
character varchar(30) NOT NULL,
PRIMARY KEY (show_date, name, birthdate, character),
FOREIGN KEY (show_date) REFERENCES ShowDates ("date"),
FOREIGN KEY (name, birthdate) REFERENCES People (name, birthdate));
CREATE TABLE BookAssignment (
name varchar(30) NOT NULL,
show_date date NOT NULL,
birthdate date NOT NULL,
book varchar(30) NOT NULL,
PRIMARY KEY (name, show_date, birthdate),
FOREIGN KEY (name, birthdate) REFERENCES People (name, birthdate),
FOREIGN KEY (show_date) REFERENCES ShowDates ("date"));
CREATE TABLE ShowWriters (
show_name varchar(30) NOT NULL,
music_writer varchar(30) NOT NULL,
script_writer varchar(30) NOT NULL,
PRIMARY KEY (show_name),
FOREIGN KEY (show_name) REFERENCES ShowNames (name));
CREATE TABLE InstrumentAssignment (
name varchar(30) NOT NULL,
birthdate date NOT NULL,
show_date date NOT NULL,
instrument varchar(30) NOT NULL,
PRIMARY KEY (name, birthdate, show_date, instrument),
FOREIGN KEY (name, birthdate) REFERENCES People (name, birthdate),
FOREIGN KEY (show_date) REFERENCES ShowDates ("date"));
CREATE TABLE FirstShow (
"date" date,
PRIMARY KEY ("date"),
FOREIGN KEY ("date") REFERENCES showdates ("date")
);