-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.sql
35 lines (32 loc) · 1.23 KB
/
schema.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
CREATE TABLE course (
id INTEGER NOT NULL,
name VARCHAR(100) NOT NULL,
CONSTRAINT pk_course PRIMARY KEY (id)
);
CREATE TABLE teacher (
id INTEGER NOT NULL,
name VARCHAR(100) NOT NULL,
CONSTRAINT pk_teacher PRIMARY KEY (id)
);
CREATE TABLE class (
id INTEGER NOT NULL,
name VARCHAR(2) NOT NULL,
teacher_id INTEGER NOT NULL,
CONSTRAINT pk_class PRIMARY KEY (id),
CONSTRAINT fk_class_teacher_id_teacher FOREIGN KEY(teacher_id) REFERENCES teacher (id)
);
CREATE TABLE student (
id INTEGER NOT NULL,
name VARCHAR(100) NOT NULL,
class_id INTEGER NOT NULL,
course_preference INTEGER NOT NULL,
partner_1_id INTEGER,
partner_2_id INTEGER,
partner_3_id INTEGER,
CONSTRAINT pk_student PRIMARY KEY (id),
CONSTRAINT fk_student_class_id_class FOREIGN KEY(class_id) REFERENCES class (id),
CONSTRAINT fk_student_course_preference_course FOREIGN KEY(course_preference) REFERENCES course (id),
CONSTRAINT fk_student_partner_1_id_student FOREIGN KEY(partner_1_id) REFERENCES student (id),
CONSTRAINT fk_student_partner_2_id_student FOREIGN KEY(partner_2_id) REFERENCES student (id),
CONSTRAINT fk_student_partner_3_id_student FOREIGN KEY(partner_3_id) REFERENCES student (id)
);