-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathschema.sql
33 lines (28 loc) · 944 Bytes
/
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
BEGIN;
CREATE TABLE student (
pk integer primary key,
first_name text NOT NULL,
last_name text,
alias text
);
CREATE TABLE assignment (
pk integer primary key,
name text NOT NULL,
due_date date,
points integer -- the point total of the assignment
);
CREATE TABLE grade (
pk integer primary key,
student_pk integer NOT NULL,
assignment_pk integer NOT NULL,
points integer, -- the points awarded to the student
-- These constraints enforce existence of foreign key and cause the rows in
-- the grade table to be deleted automatically when their referencing
-- student or assignment is deleted.
FOREIGN KEY(student_pk) REFERENCES student(pk) ON DELETE CASCADE,
FOREIGN KEY(assignment_pk) REFERENCES assignment(pk) ON DELETE CASCADE,
-- This unique constraint prevents multiple grades from being assigned to
-- the same student/assignment pair. That wouldn't make any sense.
UNIQUE (student_pk, assignment_pk)
);
COMMIT;