-
Notifications
You must be signed in to change notification settings - Fork 0
/
KP1.sql
73 lines (57 loc) · 1.74 KB
/
KP1.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
drop database if exists DB1;
create database DB1;
use DB1;
create table Degrees(
id int primary key,
name varchar(20)
);
create table Faculties(
id int auto_increment primary key,
name varchar(255)
);
create table Departments(
id int auto_increment primary key,
name varchar(255),
faculty_id int not null,
constraint foreign key(faculty_id) references Faculties(id)
);
create table Teachers(
id int auto_increment primary key,
name varchar(255) not null,
department_id int not null,
phone varchar(15),
email varchar(255),
constraint foreign key(department_id) references Departments(id)
);
create table Teacher_Degree(
teacher_id int not null,
degree_id int not null,
constraint foreign key(teacher_id) references Teachers(id),
constraint foreign key(degree_id) references Degrees(id),
constraint primary key(teacher_id,degree_id)
);
create table Rooms(
number int primary key,
capacity int not null,
numberOfComputers int not null,
hasProjector bit not null,
hasInternet bit not null,
hasBlackBoard bit not null,
hasWhiteBoard bit not null
);
create table Timetable(
id int auto_increment primary key,
date date not null,
dayOfWeek enum('Mondey','Tuesday','Wednesday','Thursday','Friday','Saterday','Sunday'),
time time not null,
constraint unique(date,dayOfWeek,time)
);
create table Room_Timetable(
room_id int not null,
timetable_id int not null,
teacher_id int not null,
constraint foreign key(room_id) references Rooms(number),
constraint foreign key(timetable_id) references Timetable(id),
constraint foreign key(teacher_id) references Teachers(id),
constraint primary key(room_id,timetable_id,teacher_id)
);