-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAttendanceAppSQL.txt
45 lines (40 loc) · 1.43 KB
/
AttendanceAppSQL.txt
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
create table instructor
(instructor_id varchar(9),
department varchar(15),
name varchar(15),
primary key (instructor_id)
);
create table student
(student_id varchar(9),
grade varchar(9) check (grade in ('Freshman', 'Sophomore', 'Junior', 'Senior')),
name varchar(15),
primary key (student_id)
);
create table course
(course_id varchar(9),
section_id varchar(9),
start_time numeric(4,0) check (start_time <= 1440),
end_time numeric(4,0) check (end_time <= 1440),
class_days varchar(9),
building varchar(20),
room_number numeric(3,0) check (room_number > 0),
allowed_misses numeric(2,0) check (allowed_misses >= 0),
primary key (course_id, section_id)
);
create table takes
(student_id varchar(9) not null,
course_id varchar(9) not null,
section_id varchar(9) not null,
misses numeric(2,0) check (misses >= 0),
primary key (student_id, course_id, section_id),
foreign key (student_id) references student (student_id) on delete cascade,
foreign key (course_id, section_id) references course (course_id, section_id) on delete cascade
);
create table teaches
(instructor_id varchar(9) not null,
course_id varchar(9) not null,
section_id varchar(9) not null,
primary key (instructor_id, course_id, section_id),
foreign key (instructor_id) references instructor (instructor_id) on delete cascade,
foreign key (course_id, section_id) references course (course_id, section_id) on delete cascade
);