-
Notifications
You must be signed in to change notification settings - Fork 0
/
initdb.sql
77 lines (66 loc) · 2.13 KB
/
initdb.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
USE db_example;
CREATE TABLE Class (
ID INT NOT NULL,
CourseID INT NOT NULL,
StudentID INT NOT NULL,
PRIMARY KEY (ID));
CREATE TABLE Course (
ID INT NOT NULL,
DepartmentID INT NOT NULL,
LecturerID INT NOT NULL,
CourseName varchar(255),
PRIMARY KEY (ID));
CREATE TABLE Department (
ID INT NOT NULL,
DepartmentName varchar(255),
Location varchar(255),
PRIMARY KEY (ID));
CREATE TABLE Lecturer (
ID INT NOT NULL,
DepartmentID INT NOT NULL,
FirstName varchar(255),
LastName varchar(255),
LecturerPhone varchar(255),
PRIMARY KEY (ID));
CREATE TABLE Student (
ID INT NOT NULL,
FirstName varchar(255),
LastName varchar(255),
StudentPhone varchar(255),
PRIMARY KEY (ID));
ALTER TABLE Class ADD CONSTRAINT FKClassStudent FOREIGN KEY (StudentID) REFERENCES Student (ID);
ALTER TABLE Class ADD CONSTRAINT FKClassCourse FOREIGN KEY (CourseID) REFERENCES Course (ID);
ALTER TABLE Course ADD CONSTRAINT FKCourseLecturer FOREIGN KEY (LecturerID) REFERENCES Lecturer (ID);
ALTER TABLE Course ADD CONSTRAINT FKCourseDepartment FOREIGN KEY (DepartmentID) REFERENCES Department (ID);
ALTER TABLE Lecturer ADD CONSTRAINT FKLecturerDepartment FOREIGN KEY (DepartmentID) REFERENCES Department (ID);
INSERT INTO Student
VALUES
(1, 'Andi', 'Barshani', '081234567789'),
(2, 'Bianka', 'Latusina', '081111222333'),
(3, 'Cecilia', 'Pandrani', '081808180810');
INSERT INTO Department
VALUES
(1, 'Computer Science', 'Murray Hall'),
(2, 'Mathematics', 'West Wing'),
(3, 'Psychology', 'Tillett Hall');
INSERT INTO Lecturer
VALUES
(1, 1, 'Jianmin', 'Zuo', '91928938392'),
(2, 2, 'Shami', 'Nejadi', '65128912833'),
(3, 3, 'Christopher', 'Joyce', '652172187382');
INSERT INTO Course
VALUES
(1, 1, 1, 'Data Structure And Algorithm'),
(2, 1, 1, 'Programming Languages'),
(3, 2, 2, 'Mathematics for Machine Learning'),
(4, 3, 3, 'Cognitive Psychology'),
(5, 3, 3, 'General Psychology');
INSERT INTO Class
VALUES
(001, 1, 1),
(002, 2, 2),
(003, 3, 3),
(004, 1, 2),
(005, 1, 3),
(006, 3, 2),
(007, 5, 3);