Starter Tutorials Blog
Tutorials and articles related to programming, computer science, technology and others.
Subscribe to Startertutorials.com's YouTube channel for different tutorial and lecture videos.
Home » Computer Science » DBMS » University Database Schema and Tables
Suryateja Pericherla Categories: DBMS. No Comments on University Database Schema and Tables
University Database Schema and Tables
Join our newsletter! - Tips, contests and more.

Having a cohesive and uniform example schema and tables is much essential to understand SQL queries. To make it happen, here we present a university database schema and the associated tables.

 

University database ER diagram

The ER diagram (conceptual design) for a university information management application is shown in the image below:

ER Diagram Example Logical Database Design

 

University database schema

The logical design (relational model), the relational schema for the university information management application is given below:

Department (Dept_ID, Dept_Name, Chair_Prof_ID)

Department_Phone (Dept_ID, Phone_Number)

Professor (Prof_ID, Prof_Name, Dept_ID)

Dependent (Prof_ID, Dep_Name, Age)

Student (Student_ID, Student_Name, Dept_ID)

Course (Course_ID, Course_Name, Prof_ID)

Enrollment (Student_ID, Course_ID)

Project_Assignment (Student_ID, Course_ID, Prof_ID)

 

 

University database SQL Queries

The DDL and DML queries for creating, inserting and updating data in tables for the university information management application are given below.

 

DDL queries

1. Department Table

CREATE TABLE Department (
    Dept_ID INT PRIMARY KEY,
    Dept_Name VARCHAR(50) NOT NULL,
    Chair_Prof_ID INT
);

 

2. Department Phone Table

CREATE TABLE Department_Phone (
    Dept_ID INT,
    Phone_Number VARCHAR(15),
    PRIMARY KEY (Dept_ID, Phone_Number),
    FOREIGN KEY (Dept_ID) REFERENCES Department(Dept_ID) ON DELETE CASCADE
);

 

3. Professor Table

CREATE TABLE Professor (
    Prof_ID INT PRIMARY KEY,
    Prof_Name VARCHAR(50) NOT NULL,
    Dept_ID INT,
    FOREIGN KEY (Dept_ID) REFERENCES Department(Dept_ID) ON DELETE SET NULL
);

 

Add Foreign Key constraint for Department Chair after Professor table is created

ALTER TABLE Department
ADD CONSTRAINT FK_Dept_Chair
FOREIGN KEY (Chair_Prof_ID) REFERENCES Professor(Prof_ID) ON DELETE SET NULL;

 

4. Dependent Table

CREATE TABLE Dependent (
    Prof_ID INT,
    Dep_Name VARCHAR(50),
    Age INT CHECK (Age >= 0),
    PRIMARY KEY (Prof_ID, Dep_Name),
    FOREIGN KEY (Prof_ID) REFERENCES Professor(Prof_ID) ON DELETE CASCADE
);

 

5. Student Table

CREATE TABLE Student (
    Student_ID INT PRIMARY KEY,
    Student_Name VARCHAR(50) NOT NULL,
    Dept_ID INT,
    FOREIGN KEY (Dept_ID) REFERENCES Department(Dept_ID) ON DELETE SET NULL
);

 

6. Course Table

CREATE TABLE Course (
    Course_ID INT PRIMARY KEY,
    Course_Name VARCHAR(50) NOT NULL,
    Prof_ID INT,
    FOREIGN KEY (Prof_ID) REFERENCES Professor(Prof_ID) ON DELETE SET NULL
);

 

7. Enrollment Table

CREATE TABLE Enrollment (
    Student_ID INT,
    Course_ID INT,
    PRIMARY KEY (Student_ID, Course_ID),
    FOREIGN KEY (Student_ID) REFERENCES Student(Student_ID) ON DELETE CASCADE,
    FOREIGN KEY (Course_ID) REFERENCES Course(Course_ID) ON DELETE CASCADE
);

 

8. Project Assignment Table

CREATE TABLE Project_Assignment (
    Student_ID INT,
    Course_ID INT,
    Prof_ID INT,
    PRIMARY KEY (Student_ID, Course_ID, Prof_ID),
    FOREIGN KEY (Student_ID, Course_ID) REFERENCES Enrollment(Student_ID, Course_ID) ON DELETE CASCADE,
    FOREIGN KEY (Prof_ID) REFERENCES Professor(Prof_ID) ON DELETE CASCADE
);

 

DML queries

Insert into Department (Chair_Prof_ID set to NULL initially to handle circular dependency)

INSERT INTO Department (Dept_ID, Dept_Name, Chair_Prof_ID) VALUES
(101, 'Computer Science', NULL),
(102, 'Electrical Engineering', NULL),
(103, 'Mechanical Engineering', NULL),
(104, 'Mathematics', NULL),
(105, 'Physics', NULL),
(106, 'Civil Engineering', NULL);

 

Insert into Professor

INSERT INTO Professor (Prof_ID, Prof_Name, Dept_ID) VALUES
(1, 'Dr. Alice Smith', 101),
(2, 'Dr. Bob Jones', 101),
(3, 'Dr. Charlie Brown', 102),
(4, 'Dr. Diana Prince', 103),
(5, 'Dr. Edward Elric', 104),
(6, 'Dr. Fiona Gallagher', 105);

 

Update Department to assign Department Chairs

UPDATE Department SET Chair_Prof_ID = 1 WHERE Dept_ID = 101;
UPDATE Department SET Chair_Prof_ID = 3 WHERE Dept_ID = 102;
UPDATE Department SET Chair_Prof_ID = 4 WHERE Dept_ID = 103;
UPDATE Department SET Chair_Prof_ID = 5 WHERE Dept_ID = 104;
UPDATE Department SET Chair_Prof_ID = 6 WHERE Dept_ID = 105;

 

Insert into Department_Phone

INSERT INTO Department_Phone (Dept_ID, Phone_Number) VALUES
(101, '555-0101'),
(101, '555-0102'),
(102, '555-0201'),
(103, '555-0301'),
(104, '555-0401'),
(105, '555-0501');

 

Insert into Dependent

INSERT INTO Dependent (Prof_ID, Dep_Name, Age) VALUES
(1, 'Emma Smith', 10),
(1, 'Liam Smith', 8),
(2, 'Noah Jones', 12),
(3, 'Olivia Brown', 5),
(4, 'Ethan Prince', 15),
(5, 'Alphonse Elric', 17);

 

Insert into Student

INSERT INTO Student (Student_ID, Student_Name, Dept_ID) VALUES
(1001, 'John Doe', 101),
(1002, 'Jane Smith', 101),
(1003, 'Alex Johnson', 102),
(1004, 'Emily Davis', 103),
(1005, 'Michael Wilson', 104),
(1006, 'Sarah Taylor', 105);

 

Insert into Course

INSERT INTO Course (Course_ID, Course_Name, Prof_ID) VALUES
(201, 'Database Systems', 1),
(202, 'Algorithms', 2),
(203, 'Circuit Analysis', 3),
(204, 'Thermodynamics', 4),
(205, 'Linear Algebra', 5),
(206, 'Quantum Mechanics', 6);

 

Insert into Enrollment

INSERT INTO Enrollment (Student_ID, Course_ID) VALUES
(1001, 201),
(1001, 202),
(1002, 201),
(1003, 203),
(1004, 204),
(1005, 205);

 

Insert into Project_Assignment

INSERT INTO Project_Assignment (Student_ID, Course_ID, Prof_ID) VALUES
(1001, 201, 1),
(1001, 202, 2),
(1002, 201, 1),
(1003, 203, 3),
(1004, 204, 4),
(1005, 205, 5);

 

University database tables

The tables in the university information management database with sample data are given below. They will be used to demonstrate different SQL queries in the future articles.

 

Department table

Dept_IDDept_NameChair_Prof_ID
101Computer Science1
102Electrical Engineering3
103Mechanical Engineering4
104Mathematics5
105Physics6
106Civil EngineeringNULL

 

Professor table

Prof_IDProf_NameDept_ID
1Dr. Alice Smith101
2Dr. Bob Jones101
3Dr. Charlie Brown102
4Dr. Diana Prince103
5Dr. Edward Elric104
6Dr. Fiona Gallagher105

 

Department_Phone table

Dept_IDPhone_Number
101555-0101
101555-0102
102555-0201
103555-0301
104555-0401
105555-0501

 

Dependent table

Prof_IDDep_NameAge
1Emma Smith10
1Liam Smith8
2Noah Jones12
3Olivia Brown5
4Ethan Prince15
5Alphonse Elric17

 

Student table

Student_IDStudent_NameDept_ID
1001John Doe101
1002Jane Smith101
1003Alex Johnson102
1004Emily Davis103
1005Michael Wilson104
1006Sarah Taylor105

 

Course table

Course_IDCourse_NameProf_ID
201Database Systems1
202Algorithms2
203Circuit Analysis3
204Thermodynamics4
205Linear Algebra5
206Quantum Mechanics6

 

Enrollment table

Student_IDCourse_ID
1001201
1001202
1002201
1003203
1004204
1005205

 

Project_Assignment table

Student_IDCourse_IDProf_ID
10012011
10012022
10022011
10032033
10042044
10052055

 

How useful was this post?

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook
Twitter
Pinterest
Youtube
Instagram
Blogarama - Blog Directory