-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtablesetup.sql
58 lines (52 loc) · 1.45 KB
/
tablesetup.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
drop table IF EXISTS Professor;
create table Professor (
pid INTEGER AUTO_INCREMENT PRIMARY KEY,
fname VARCHAR(15) NOT NULL,
lname VARCHAR(25) NOT NULL,
UNIQUE (fname, lname)
);
drop table IF EXISTS Department;
create table Department (
dno INTEGER NOT NULL PRIMARY KEY,
dname VARCHAR(50) NOT NULL,
UNIQUE (dno,dname)
);
drop table IF EXISTS Department_affiliation;
create table Department_affiliation (
pid INTEGER NOT NULL,
dno INTEGER NOT NULL,
FOREIGN KEY (pid)
REFERENCES Professor(pid),
FOREIGN KEY (dno)
REFERENCES Department(dno),
UNIQUE (pid,dno)
);
drop table IF EXISTS Course;
create table Course (
dno INTEGER NOT NULL,
cno INTEGER NOT NULL PRIMARY KEY,
cname TEXT NOT NULL,
FOREIGN KEY (dno)
REFERENCES Department(dno),
UNIQUE (dno, cno)
);
drop table IF EXISTS Course_instance;
create table Course_instance (
dno INTEGER NOT NULL,
cno INTEGER NOT NULL,
semester VARCHAR(1) NOT NULL,
year VARCHAR(4) NOT NULL,
pid INTEGER NOT NULL,
rating FLOAT NOT NULL,
summary TEXT NOT NULL,
FOREIGN KEY (dno)
REFERENCES Department(dno),
FOREIGN KEY (cno)
REFERENCES Course(cno),
FOREIGN KEY (pid)
REFERENCES Professor(pid)
);
create view Course_complete AS
SELECT ci.year AS year, ci.semester AS semester, dname, d.dno AS dno, c.cno AS cno, fname, lname, rating, summary
FROM Course_instance AS ci, Course AS c, Professor AS p, Department AS d
WHERE ci.dno = d.dno AND ci.cno = c.cno AND ci.pid = p.pid;