كود:
Create table Student (
studentId int Primary Key ,
firstName varchar(30) not null,
lastName varchar(30) not null,
profilepic blob,
gender varchar(1),
dob date,
address varchar(200),
deptId int,
homepage varchar(70) default null,
yearEnrolled varchar(15) not null,
overallGPA float (3,2),
foreign key (deptId) references Department(dept_id) );
Create table Login (
username varchar(20) not null UNIQUE,
password varchar(20) not null,
type varchar(1) not null,
studInstId int not null AUTO_INCREMENT Primary Key
);
Create table Instructor(
instId int Primary Key ,
firstName varchar(30) not null,
lastName varchar(30) not null,
profilepic blob,
gender varchar(1) not null,
dob date not null,
address varchar(200) not null,
homepage varchar(70) default null,
yearEnrolled varchar(15) not null
)
Create table Department (
deptId int primary key,
deptName varchar(50) not null
)
Create table Course (
courseId int,
courseName varchar(50),
term varchar(15) ,
deptId int,
credits int not null,
textbook varchar(50) default null,
refTextbook varchar(50) default null,
courselink varchar(50) default null,
primary key (courseId, term),
foreign key (deptId) references Department(dept_id),
);
Create table Prerequisites (
courseId varchar(15),
prereqId varchar(15),
foreign key (courseId) references Course(courseId),
foreign key (prereqId) references Course(courseId)
);
Create able Coursestaken (
studentId int,
courseId varchar(10),
term varchar(15),
grade varchar(1) default null ,
foreign key (studentId) references Student,
foreign key (courseId) references Course,
foreign key (term) references Course(term) );
Create table InstructorDept (
instId int,
deptId int,
foreign key (instId) references Instructor,
foreign key (deptId) references Department
);
Create table InstructorCourses (
instId int,
courseId varchar(15),
term varchar(15),
foreign key (instId) references Instructor,
foreign key (courseId) references Courses,
foreign key (term) references Course(term)
);
Create table Classroom (
classId varchar(10) primary key,
location varchar(30) not null,
maxCapacity int not null,
seatsLeft int not null
);
Create table ClassCourse (
classId int not null,
courseId varchar(15) not null,
period int not null,
day varchar(1) not null,
term varchar(15) not null,
foreign key (classId) references Classroom(classId),
foreign key (courseId) references Course(courseId),
foreign key (term) references Course(term)
);
العلاقات فى القاعدة