-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_setup.sql
59 lines (53 loc) · 1.21 KB
/
db_setup.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
CREATE DATABASE racezers_db
CREATE TABLE exercises
(
id INTEGER UNIQUE NOT NULL,
name VARCHAR(45) NOT NULL,
description VARCHAR(255),
point_scale DECIMAL(10, 2) NOT NULL,
calories_burned DECIMAL(10, 2),
PRIMARY KEY (id)
);
CREATE TABLE competitors
(
id INTEGER NOT NULL,
hipchat_id INTEGER,
active BIT NOT NULL,
name VARCHAR(45),
email VARCHAR(255),
PRIMARY KEY (id),
INDEX(hipchat_ID(10))
);
CREATE TABLE competitions
(
id INTEGER NOT NULL,
active BIT NOT NULL,
name VARCHAR(45),
description VARCHAR(255),
goal INTEGER,
start_date DATETIME,
end_date DATETIME,
PRIMARY KEY (id)
);
CREATE TABLE records
(
id INTEGER NOT NULL,
competitor_id INTEGER NOT NULL,
competition_id INTEGER NOT NULL,
exercise_id INTERGER NOT NULL,
count INTEGER NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (competition_id) REFERENCES competitions(id),
FOREIGN KEY (competitor_id) REFERENCES competitors(id),
FOREIGN KEY (exercise_id) REFERENCES exercise(id)
);
CREATE TABLE competitionTotals
(
id NOT NULL,
competition_id NOT NULL,
competitor_id NOT NULL,
score DECIMAL(10) NOT NULL,
PRIMARY KEY (id)
FOREIGN KEY (competition_id) REFERENCES competitions(id),
FOREIGN KEY (competitor_id) REFERENCES competitors(id)
)