Database Assignment
Database Assignment
Entity–Relationship Diagram
The ER diagram above consists of five entities: Student, Course, Lecturer, Department, and
Enrollment. Each entity contains attributes relevant to the university’s operations.
Normalization (3NF)
Normalization was applied to ensure the database design is efficient, consistent, and free from
redundancy. The process followed the standard forms up to Third Normal Form (3NF):
Unnormalized Form (UNF): Initially, all student, course, lecturer, department, and
enrollment details could be stored in a single large table. This design contained repeating
groups and redundant data.
First Normal Form (1NF): The data was reorganized so that each attribute contains
atomic values only. Repeating groups were removed by separating information into
distinct tables such as Student, Course, Department, Lecturer, and Enrollment.
Second Normal Form (2NF): Partial dependencies were eliminated. In the Enrollment
table, attributes like Semester and Grade depend on the full primary key (EnrollmentID
or the combination of StudentID and CourseID), not just part of it. This ensures that all
non-key attributes depend on the whole key.
Third Normal Form (3NF): Transitive dependencies were removed. For example,
Department information was separated from Course and Lecturer tables instead of being
stored in Enrollment. This prevents duplication and ensures that non-key attributes
depend only on the primary key of their table.
Final Normalized Tables
Student (StudentID, Name, DOB, Gender, Email, Phone)
Course (CourseID, Title, Credits, DepartmentID)
Department (DepartmentID, Name, Faculty, Location)
Lecturer (LecturerID, Name, DepartmentID, Email, Phone)
Enrollment (EnrollmentID, StudentID, CourseID, Semester, Grade)
By normalizing up to 3NF, the database design avoids redundancy, ensures data integrity, and
supports efficient querying. Each entity is stored in its own table, relationships are enforced
through foreign keys, and attributes depend only on their respective primary keys.
SQL Statements to Create Database and Apply Constraints
Database Creation
CREATE DATABASE UniversityDB;
USE UniversityDB;
StudentID
CREATE TABLE Student ( INT PRIMARY KEY, CREATE TABLE Enrollment (
StudentIDName
INT PRIMARY KEY, EnrollmentID INT PRIMARY KEY,
VARCHAR(45) NOT NULL,
StudentID INT NOT NULL,
Name VARCHAR(45) NOT NULL,
DOB DATE NOT NULL,
CourseID INT NOT NULL,
DOB DATE NOT NULL,
Gender VARCHAR(10) NOT NULL, Semester VARCHAR(45) NOT NULL,
Gender VARCHAR(10) NOT NULL,
Email VARCHAR(45) UNIQUE, Grade VARCHAR(5),
Email VARCHAR(45) UNIQUE,
FOREIGN KEY (StudentID) REFERENCES Student(StudentID),
Phone VARCHAR(20)
Phone VARCHAR(20)
FOREIGN KEY (CourseID) REFERENCES Course(CourseID)
);
);
Student Table
Enrollment Table
Primary Key: StudentID uniquely identifies each student. Primary Key: EnrollmentID uniquely identifies each
NOT NULL: Name, DOB, and Gender must always be provided. enrollment record.
UNIQUE: Email prevents duplicate entries. NOT NULL: StudentID, CourseID, and Semester must always
be provided.
Foreign Keys: StudentID links to Student, CourseID links to
Course — enforcing relationships
This section presents the SQL statements used to create the UniversityDB schema. Primary keys
uniquely identify records, foreign keys enforce relationships between tables, NOT NULL ensures
required fields are always filled, and UNIQUE prevents duplicate values. Together, these
constraints guarantee data integrity and consistency in the database.
The schema was implemented in MySQL Workbench using CREATE TABLE statements
Figure 2 shows action output for CREATE TABLE Department figure 3 shows action output for CREATE TABLE Employee
Figure 4 shows Action Output for CREATE TABLE Project figure 5 shows Action Output for CREATE TABLE Dependent
Figure 6 shows action output for CREATE TABLE Works_On
Verification
Figure 7 SHOW TABLES result showing Department, Employee, Project, Dependent, Works_On
DESCRIBE TableName; was executed to display column definitions and constraints.
INSERT INTO Department VALUES (1, 'IT', 101, 2001, '2020-01-01', 'Lusaka');
INSERT INTO Employee VALUES (1, 'SSN001', 'John', 'Street 1', 5000, 'M', '1990-01-01', 1, NULL);
INSERT INTO Project VALUES (1, 'Payroll System', 1001, 'Lusaka', 1);
INSERT INTO Dependent VALUES (1, 'Mary', 'F', '2015-05-05', 'Daughter', 1);
The company database was successfully conceptualized, designed, and implemented. The ER
diagram illustrates the relationships, the relational schema enforces integrity, and the SQL
implementation confirms functionality.