UniCon-Database is a repo containing all info related to UniCon's database
id
: SERIAL PRIMARY KEYname
: VARCHAR(255) NOT NULLshortname
: VARCHAR(10) NOT NULL UNIQUE
id
: SERIAL PRIMARY KEYname
: VARCHAR(255) NOT NULL UNIQUEshortname
: VARCHAR(3) NOT NULL UNIQUEsubject_id
: INTEGER REFERENCES subject(id) NOT NULL
id
: SERIAL PRIMARY KEYdepartment_name
: VARCHAR(255) NOT NULL UNIQUEhod_id
: INTEGER REFERENCES faculty(id) NOT NULL UNIQUE
id
: SERIAL PRIMARY KEYbatch_name
: VARCHAR(255) NOT NULLdep_id
: INTEGER REFERENCES department(id) NOT NULL- UNIQUE(batch_name, dep_id)
id
: SERIAL PRIMARY KEYstart_time
: TIME NOT NULLend_time
: TIME NOT NULL- UNIQUE(start_time, end_time)
id
: SERIAL PRIMARY KEYroom_no
: VARCHAR(10) NOT NULLroom_type
: room_type NOT NULL- UNIQUE(room_no, room_type)
id
: SERIAL PRIMARY KEYtime_id
: INTEGER REFERENCES time_slot(id) NOT NULLday
: day_of_week NOT NULLbat_id
: INTEGER REFERENCES batch(id) NOT NULLfac_id
: INTEGER REFERENCES faculty(id) NOT NULLroom_id
: INTEGER REFERENCES room(id) NOT NULL- UNIQUE(time_id, bat_id, fac_id, room_id)
id
: SERIAL PRIMARY KEYtime_id
: INTEGER REFERENCES time_slot(id) NOT NULLday
: day_of_week NOT NULLbat_id
: INTEGER REFERENCES batch(id) NOT NULLfac_id
: INTEGER REFERENCES faculty(id) NOT NULLroom_id
: INTEGER REFERENCES room(id) NOT NULL- UNIQUE(time_id, bat_id, fac_id, room_id)
id
: SERIAL PRIMARY KEYdegree_name
: VARCHAR(100) UNIQUE NOT NULL
id
: SERIAL PRIMARY KEYbranch_name
: VARCHAR(10) UNIQUE NOT NULLdegree_id
: INTEGER REFERENCES degree(id) NOT NULL
id
: SERIAL PRIMARY KEYexam_date
: DATE NOT NULLsem
: INTEGER NOT NULLtest_phase
: test_phase NOT NULLsubject_id
: INTEGER REFERENCES subject(id) NOT NULLbranch_id
: INTEGER REFERENCES branch(id) NOT NULLtime_id
: INTEGER REFERENCES time_slot(id) NOT NULL- UNIQUE(exam_date, subject_id, branch_id, sem)
id
: SERIAL PRIMARY KEYenrollment_no
: BIGINT NOT NULL UNIQUEstudent_name
: VARCHAR(50) NOT NULLbranch_id
: INTEGER REFERENCES branch(id) NOT NULL
id
: SERIAL PRIMARY KEYbatch_id
: INTEGER REFERENCES batch(id)student_id
: INTEGER REFERENCES basic_student_details(id)sem
: INTEGER NOT NULLroll_no
: INTEGER NOT NULL
-- Create Subject Table
CREATE TABLE subject (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
shortname VARCHAR(10) NOT NULL UNIQUE
);
-- Create Faculty Table
CREATE TABLE faculty (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL UNIQUE,
shortname VARCHAR(3) NOT NULL UNIQUE,
subject_id INTEGER REFERENCES subject(id) NOT NULL
);
-- Create Department Table
CREATE TABLE department (
id SERIAL PRIMARY KEY,
department_name VARCHAR(255) NOT NULL UNIQUE,
hod_id INTEGER REFERENCES faculty(id) NOT NULL UNIQUE
);
-- Create Batch Table
CREATE TABLE batch (
id SERIAL PRIMARY KEY,
batch_name VARCHAR(255) NOT NULL,
dep_id INTEGER REFERENCES department(id) NOT NULL,
UNIQUE(batch_name, dep_id)
);
-- Create Time Slot Table
CREATE TABLE time_slot (
id SERIAL PRIMARY KEY,
start_time TIME NOT NULL,
end_time TIME NOT NULL,
UNIQUE(start_time, end_time)
);
-- Create Room Table
CREATE TYPE room_type AS ENUM('Classroom', 'Physics-Lab', 'Computer-Lab');
CREATE TABLE room (
id SERIAL PRIMARY KEY,
room_no VARCHAR(10) NOT NULL,
room_type room_type NOT NULL,
UNIQUE(room_no, room_type)
);
-- Create Timetable Table
CREATE TYPE day_of_week AS ENUM ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');
CREATE TABLE timetable (
id SERIAL PRIMARY KEY,
time_id INTEGER REFERENCES time_slot(id) NOT NULL,
day day_of_week NOT NULL,
bat_id INTEGER REFERENCES batch(id) NOT NULL,
fac_id INTEGER REFERENCES faculty(id) NOT NULL,
room_id INTEGER REFERENCES room(id) NOT NULL,
UNIQUE(time_id, day, bat_id, fac_id, room_id),
UNIQUE (time_id, day, room_id),
UNIQUE (time_id, day, bat_id),
UNIQUE (time_id, day, fac_id)
);
CREATE TABLE proxy_timetable (
id SERIAL PRIMARY KEY,
time_id INTEGER REFERENCES time_slot(id) NOT NULL,
day day_of_week NOT NULL,
bat_id INTEGER REFERENCES batch(id) NOT NULL,
fac_id INTEGER REFERENCES faculty(id) NOT NULL,
room_id INTEGER REFERENCES room(id) NOT NULL,
UNIQUE(time_id, day, bat_id, fac_id, room_id),
UNIQUE (time_id, day, room_id),
UNIQUE (time_id, day, bat_id),
UNIQUE (time_id, day, fac_id)
);
-- Create Degree Table
CREATE TABLE degree (
id SERIAL PRIMARY KEY,
degree_name VARCHAR(100) UNIQUE NOT NULL
);
-- Create Branch Table
CREATE TABLE branch (
id SERIAL PRIMARY KEY,
branch_name VARCHAR(10) UNIQUE NOT NULL,
degree_id INTEGER REFERENCES degree(id) NOT NULL
);
-- Create Exam Timetable Table
CREATE TYPE test_phase AS ENUM('t1','t2','t3','t4','t5','test','mid-sem','end-sem');
CREATE TABLE exam_timetable (
id SERIAL PRIMARY KEY,
exam_date DATE NOT NULL,
sem INTEGER NOT NULL,
test_phase test_phase NOT NULL,
subject_id INTEGER REFERENCES subject(id) NOT NULL,
branch_id INTEGER REFERENCES branch(id) NOT NULL,
time_id INTEGER REFERENCES time_slot(id) NOT NULL,
UNIQUE(exam_date, subject_id, branch_id, sem)
);
-- Create Basic Student Details Table
CREATE TABLE basic_student_details (
id SERIAL PRIMARY KEY,
enrollment_no BIGINT NOT NULL UNIQUE,
student_name VARCHAR(50) NOT NULL,
branch_id INTEGER REFERENCES branch(id) NOT NULL
);
-- Create Dynamic Student Details Table
CREATE TABLE dynamic_student_details (
id SERIAL PRIMARY KEY,
batch_id INTEGER REFERENCES batch(id),
student_id INTEGER REFERENCES basic_student_details(id),
sem INTEGER NOT NULL,
roll_no INTEGER NOT NULL
);
-- End of SQL script