-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4. Tabel Creation Codes.sql
169 lines (152 loc) · 4.02 KB
/
4. Tabel Creation Codes.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
create database olympic_games;
CREATE TABLE Equipment
(
Item_id INT NOT NULL,
Name_e VARCHAR(30) NOT NULL,
Cost INT NOT NULL,
number_of_equipment INT NOT NULL,
PRIMARY KEY (Item_id)
);
CREATE TABLE Sponsors
(
Name_s VARCHAR(30) NOT NULL,
Sponsor_id INT NOT NULL,
PRIMARY KEY (Sponsor_id)
);
CREATE TABLE Transport
(
Vehicle_id VARCHAR(10) NOT NULL,
Capacity INT NOT NULL,
PRIMARY KEY (Vehicle_id)
);
CREATE TABLE Location
(
Name_L VARCHAR(30) NOT NULL,
Zip_code INT NOT NULL,
PRIMARY KEY (Name_L, Zip_code)
);
CREATE TABLE Arena
(
Name_L VARCHAR(30) NOT NULL,
Zip_code INT NOT NULL,
Capacity INT NOT NULL,
PRIMARY KEY (Name_L, Zip_code),
FOREIGN KEY (Name_L, Zip_code) REFERENCES Location(Name_L, Zip_code)
);
CREATE TABLE Accommodation
(
Name_L VARCHAR(30) NOT NULL,
Zip_code INT NOT NULL,
PRIMARY KEY (Name_L, Zip_code),
FOREIGN KEY (Name_L, Zip_code) REFERENCES Location(Name_L, Zip_code)
);
CREATE TABLE Tickets
(
Seat_Number INT NOT NULL,
Ticket_number INT NOT NULL,
date_t DATE NOT NULL,
cost INT NOT NULL,
Name_L VARCHAR(30) NOT NULL,
Zip_code INT NOT NULL,
PRIMARY KEY (Ticket_number, date_t),
FOREIGN KEY (Name_L, Zip_code) REFERENCES Arena(Name_L, Zip_code)
);
CREATE TABLE Fixtures
(
Match_id VARCHAR(10) NOT NULL,
Name_sports VARCHAR(30) NOT NULL,
Time_f VARCHAR(30) NOT NULL,
Date_f DATE NOT NULL,
Name_L VARCHAR(30) NOT NULL,
Zip_code INT NOT NULL,
PRIMARY KEY (Match_id),
FOREIGN KEY (Name_L, Zip_code) REFERENCES Arena(Name_L, Zip_code)
);
CREATE TABLE Result
(
Country VARCHAR(30) NOT NULL,
Ranking INT NOT NULL,
Match_id VARCHAR(10) NOT NULL,
PRIMARY KEY (Country, Match_id),
FOREIGN KEY (Match_id) REFERENCES Fixtures(Match_id)
);
CREATE TABLE Sponsored_by
(
Sponsor_id INT NOT NULL,
Match_id VARCHAR(10) NOT NULL,
FOREIGN KEY (Sponsor_id) REFERENCES Sponsors(Sponsor_id),
FOREIGN KEY (Match_id) REFERENCES Fixtures(Match_id)
);
CREATE TABLE Requires
(
Item_id INT NOT NULL,
Match_id VARCHAR(10) NOT NULL,
FOREIGN KEY (Item_id) REFERENCES Equipment(Item_id),
FOREIGN KEY (Match_id) REFERENCES Fixtures(Match_id)
);
CREATE TABLE Person
(
Name VARCHAR(30) NOT NULL,
Person_id VARCHAR(10) NOT NULL,
Gender VARCHAR(10),
Name_L VARCHAR(30) NOT NULL,
Zip_code INT NOT NULL,
PRIMARY KEY (Person_id),
FOREIGN KEY (Name_L, Zip_code) REFERENCES Accommodation(Name_L, Zip_code)
);
CREATE TABLE Official
(
Medal_presenter CHAR(1) NOT NULL,
Referee CHAR(1) NOT NULL,
Judge CHAR(1) NOT NULL,
Person_id VARCHAR(10) NOT NULL,
PRIMARY KEY (Person_id),
FOREIGN KEY (Person_id) REFERENCES Person(Person_id)
);
CREATE TABLE Athlete
(
Country VARCHAR(30) NOT NULL,
Sport VARCHAR(30) NOT NULL,
JerseyNumber INT NOT NULL,
Person_id VARCHAR(10) NOT NULL,
PRIMARY KEY (Person_id),
FOREIGN KEY (Person_id) REFERENCES Person(Person_id)
);
CREATE TABLE Participates_organises
(
Match_id VARCHAR(10) NOT NULL,
Person_id VARCHAR(10) NOT NULL,
FOREIGN KEY (Match_id) REFERENCES Fixtures(Match_id),
FOREIGN KEY (Person_id) REFERENCES Person(Person_id)
);
CREATE TABLE Travels_from
(
Time_D VARCHAR(10) NOT NULL,
Date_D DATE NOT NULL,
Name_L VARCHAR(30) NOT NULL,
Zip_code INT NOT NULL,
Person_id VARCHAR(10) NOT NULL,
Vehicle_id VARCHAR(10) NOT NULL,
FOREIGN KEY (Name_L, Zip_code) REFERENCES Location(Name_L, Zip_code),
FOREIGN KEY (Person_id) REFERENCES Person(Person_id),
FOREIGN KEY (Vehicle_id) REFERENCES Transport(Vehicle_id)
);
CREATE TABLE Travels_to
(
Time_A VARCHAR(10) NOT NULL,
Date_A DATE NOT NULL,
Name_L VARCHAR(30) NOT NULL,
Zip_code INT NOT NULL,
Person_id VARCHAR(10) NOT NULL,
Vehicle_id VARCHAR(10) NOT NULL,
FOREIGN KEY (Name_L, Zip_code) REFERENCES Location(Name_L, Zip_code),
FOREIGN KEY (Person_id) REFERENCES Person(Person_id),
FOREIGN KEY (Vehicle_id) REFERENCES Transport(Vehicle_id)
);
CREATE TABLE Uses
(
Vehicle_id VARCHAR(10) NOT NULL,
Person_id VARCHAR(10) NOT NULL,
FOREIGN KEY (Vehicle_id) REFERENCES Transport(Vehicle_id),
FOREIGN KEY (Person_id) REFERENCES Person(Person_id)
);