-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path101-init.sql
48 lines (37 loc) · 1.51 KB
/
101-init.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
-- Initial
DROP TABLE IF EXISTS corrections;
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS projects;
CREATE TABLE IF NOT EXISTS users (
id int not null AUTO_INCREMENT,
name varchar(255) not null,
average_score float default 0,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS projects (
id int not null AUTO_INCREMENT,
name varchar(255) not null,
weight int default 1,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS corrections (
user_id int not null,
project_id int not null,
score float default 0,
KEY `user_id` (`user_id`),
KEY `project_id` (`project_id`),
CONSTRAINT fk_user_id FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
CONSTRAINT fk_project_id FOREIGN KEY (`project_id`) REFERENCES `projects` (`id`) ON DELETE CASCADE
);
INSERT INTO users (name) VALUES ("Bob");
SET @user_bob = LAST_INSERT_ID();
INSERT INTO users (name) VALUES ("Jeanne");
SET @user_jeanne = LAST_INSERT_ID();
INSERT INTO projects (name, weight) VALUES ("C is fun", 1);
SET @project_c = LAST_INSERT_ID();
INSERT INTO projects (name, weight) VALUES ("Python is cool", 2);
SET @project_py = LAST_INSERT_ID();
INSERT INTO corrections (user_id, project_id, score) VALUES (@user_bob, @project_c, 80);
INSERT INTO corrections (user_id, project_id, score) VALUES (@user_bob, @project_py, 96);
INSERT INTO corrections (user_id, project_id, score) VALUES (@user_jeanne, @project_c, 91);
INSERT INTO corrections (user_id, project_id, score) VALUES (@user_jeanne, @project_py, 73);