-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreate DB.sql
More file actions
103 lines (92 loc) · 3.46 KB
/
Create DB.sql
File metadata and controls
103 lines (92 loc) · 3.46 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
-- 1. Create the Database
DROP DATABASE IF EXISTS universityroutinedb;
CREATE DATABASE UniversityRoutineDB;
-- 2. Use the Database
USE UniversityRoutineDB;
-- 3. Create the Departments Table
CREATE TABLE Departments (
DepartmentID INT PRIMARY KEY AUTO_INCREMENT,
DepartmentName VARCHAR(100) NOT NULL,
DepartmentCode VARCHAR(100) NOT NULL
);
-- 4. Create the Professors Table
-- Create the Professors Table with ShortName
CREATE TABLE Professors (
ProfessorID INT PRIMARY KEY AUTO_INCREMENT,
FirstName VARCHAR(50) NOT NULL,
LastName VARCHAR(50) NOT NULL,
ShortName VARCHAR(10) NOT NULL, -- Short name for the professor
DepartmentID INT,
Email VARCHAR(100),
Phone VARCHAR(20),
Status ENUM('Active', 'LPR', 'Leave', 'PRL', 'Retired') DEFAULT 'Active',
FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID)
);
-- 5. Create the Semesters Table
CREATE TABLE Semesters (
SemesterID INT PRIMARY KEY AUTO_INCREMENT,
SemesterName VARCHAR(50) NOT NULL,
SemesterCode VARCHAR(5) NOT NULL,
IsActive BOOLEAN DEFAULT FALSE -- Indicates if the semester is currently running
);
-- 6. Create the Courses Table
CREATE TABLE Courses (
CourseID INT PRIMARY KEY AUTO_INCREMENT,
CourseName VARCHAR(100) NOT NULL,
CourseCode VARCHAR(20) NOT NULL, -- Course code starting with 'CSE'
DepartmentID INT,
Credits INT,
CourseType ENUM('Theory', 'Lab') NOT NULL, -- Specifies the type of course
IsActive BOOLEAN DEFAULT FALSE, -- Indicates if the course is currently active
FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID)
);
-- 7. Create CourseProfessors Table
CREATE TABLE CourseProfessors (
CourseProfessorID INT PRIMARY KEY AUTO_INCREMENT,
CourseID INT,
ProfessorID INT,
FOREIGN KEY (CourseID) REFERENCES Courses(CourseID),
FOREIGN KEY (ProfessorID) REFERENCES Professors(ProfessorID)
);
-- 8. Create SemestersCourses Table
CREATE TABLE SemestersCourses (
SemesterCourseID INT PRIMARY KEY AUTO_INCREMENT,
SemesterID INT,
CourseID INT,
FOREIGN KEY (SemesterID) REFERENCES Semesters(SemesterID),
FOREIGN KEY (CourseID) REFERENCES Courses(CourseID)
);
-- 7. Create the Rooms Table
CREATE TABLE Rooms (
RoomID INT PRIMARY KEY AUTO_INCREMENT,
RoomNumber VARCHAR(10) NOT NULL,
Capacity INT NOT NULL,
RoomType ENUM('Classroom', 'Lab') NOT NULL, -- Specifies whether the room is a classroom or a lab
Status ENUM('Available', 'Not Available') DEFAULT 'Available'
);
-- 8. Create the Course Room Table
CREATE TABLE CourseRoom (
CourseRoomID INT AUTO_INCREMENT PRIMARY KEY,
CourseID INT NOT NULL,
RoomID INT NOT NULL,
CONSTRAINT fk_course FOREIGN KEY (CourseID) REFERENCES Courses(CourseID),
CONSTRAINT fk_room FOREIGN KEY (RoomID) REFERENCES Rooms(RoomID)
);
-- 9. Create the Preference Table
CREATE TABLE Preferences (
PreferenceID INT PRIMARY KEY AUTO_INCREMENT,
ProfessorID INT,
DayHalf ENUM('1st Half', '2nd Half'), -- Indicates first or second half of the day
Preferred BOOLEAN DEFAULT TRUE, -- Indicates if it's a preferred half
FOREIGN KEY (ProfessorID) REFERENCES Professors(ProfessorID)
);
-- 10. Create the Schedules Table
CREATE TABLE Schedules (
ScheduleID INT PRIMARY KEY AUTO_INCREMENT,
CourseID INT,
TimeSlot INT,
RoomID INT,
FOREIGN KEY (CourseID) REFERENCES Courses(CourseID),
FOREIGN KEY (RoomID) REFERENCES Rooms(RoomID),
UNIQUE (CourseID, TimeSlotID, RoomID) -- Prevents scheduling conflicts
);