-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_table.sql
110 lines (100 loc) · 2.48 KB
/
create_table.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
CREATE DATABASE IF NOT EXISTS felist;
use felist;
CREATE TABLE IF NOT EXISTS Region(
city char(50),
province char(50),
PRIMARY KEY(city, province)
);
CREATE TABLE IF NOT EXISTS Regatta(
regattaId int,
raceLength int,
name char(40),
location char(30),
raceDate date,
regionCity char(50) NOT NULL,
regionProvince char(50) NOT NULL,
PRIMARY KEY(regattaId),
FOREIGN KEY(regionCity, regionProvince) REFERENCES Region(city, province)
ON DELETE NO ACTION
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS User(
username char(20) ,
encryptedPassword char(100),
PRIMARY KEY(username)
);
CREATE TABLE IF NOT EXISTS Team(
teamId int,
name char(50),
practiceCost decimal,
username char(20) NOT NULL,
regionCity char(50) NOT NULL,
regionProvince char(50) NOT NULL,
PRIMARY KEY(teamId),
FOREIGN KEY(username) REFERENCES user(username)
ON DELETE NO ACTION
ON UPDATE CASCADE,
FOREIGN KEY(regionCity, regionProvince) REFERENCES Region(city, province)
ON DELETE NO ACTION
ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS Member(
memberId int,
memberName char(30),
weight float,
height float,
role char(20),
paddleSide char(10),
dateOfBirth date,
teamId int NOT NULL,
PRIMARY KEY(memberId),
FOREIGN KEY(teamId) REFERENCES Team(teamId)
ON DELETE NO ACTION
ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS HasPractice(
practiceId int,
dayOfWeek char(10),
location char(50),
startTime time,
duration int,
teamId int,
PRIMARY KEY(practiceId, teamId),
FOREIGN KEY(teamId) REFERENCES Team(teamId)
ON UPDATE CASCADE
ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS RaceResult(
resultId int,
ranking int,
timeSeconds float,
regattaId int NOT NULL,
teamId int,
PRIMARY KEY(teamId, resultId),
FOREIGN KEY(regattaId) REFERENCES Regatta(regattaId)
ON DELETE CASCADE
ON UPDATE CASCADE,
FOREIGN KEY(teamId) REFERENCES Team(teamId)
ON DELETE CASCADE
ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS PaddleOwns(
memberId int,
brand char(20),
type char(20),
size int,
colour char(15),
PRIMARY KEY(memberId, brand),
FOREIGN KEY(memberId) REFERENCES Member(memberId)
ON UPDATE CASCADE
ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS Participates(
teamId int,
regattaId int,
PRIMARY KEY(teamId, regattaId),
FOREIGN KEY(teamId) REFERENCES Team(teamId)
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY(regattaId) REFERENCES Regatta(regattaId)
);