0% found this document useful (0 votes)
5 views11 pages

Lab 3

This lab focuses on the Entity-Relationship (ER) Model, essential for database design, using a University Management System as a comprehensive example. Students will learn to identify entities, attributes, and relationships, develop ER diagrams, and implement SQL commands for database creation. The lab also includes exercises for designing ER models for various systems, ensuring practical application of the concepts learned.

Uploaded by

Umair Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views11 pages

Lab 3

This lab focuses on the Entity-Relationship (ER) Model, essential for database design, using a University Management System as a comprehensive example. Students will learn to identify entities, attributes, and relationships, develop ER diagrams, and implement SQL commands for database creation. The lab also includes exercises for designing ER models for various systems, ensuring practical application of the concepts learned.

Uploaded by

Umair Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Database Systems LAB​ ​ SPRINIG 2025

Lab 3: Database Design – ER Model

1. Introduction

This lab introduces the fundamentals of the Entity-Relationship (ER) Model, a crucial step in
database design. Students will explore the symbols used in ER diagrams, understand their
significance, and apply them through a comprehensive example of a University Management
System. The manual covers every aspect of ER modeling, including identifying entities,
attributes, relationships, cardinality, participation constraints, weak entities, and multivalued
attributes. It concludes with SQL implementations, corresponding table structures, a full
system-level ER diagram, and a symbols reference sheet. The goal is to ensure students gain both
theoretical and practical expertise.

2. Learning Outcomes

By the end of this lab, students will be able to:

●​ Understand and use standard ER diagram symbols effectively.


●​ Identify entities, attributes, and relationships from a given scenario.
●​ Develop a complete ER diagram with cardinality and participation constraints.
●​ Model weak entities, multivalued attributes, and derived attributes.
●​ Translate real-world problems into conceptual and relational database designs.
●​ Write and execute SQL commands to implement the ER model into a database.
●​ Relate SQL table structures to the ER model for better understanding.
●​ Refer to a comprehensive symbol cheatsheet for quick guidance.

3. Lab Setup

●​ Software Requirements:
o​ Online Tools: Lucidchart, draw.io, Creately
o​ Offline Tools: Microsoft Visio or graph paper for manual sketches
o​ Database Management System: MySQL Workbench or PostgreSQL with
pgAdmin

Page 1 of 11
Database Systems LAB​ ​ SPRINIG 2025

4. ER Diagram Symbols and Their Usage

ER diagrams use specific symbols to represent various components. Understanding these


symbols is essential before creating an ER model.

4.1 Standard Symbols Overview

Symbol Shape Description


Represents an entity set (e.g., Student,
Entity Rectangle
Course)
Weak Entity Double Rectangle Entity dependent on another entity
Describes a property of an entity or
Attribute Oval
relationship
Attribute with multiple values (e.g., Phone
Multivalued Attribute Double Oval
Numbers)
Attribute derived from other attributes (e.g.,
Derived Attribute Dashed Oval
Age)
Relationship Diamond Represents associations between entities
Identifying Relationship Double Diamond Connects weak entities to their owners
Connects attributes, entities, and
Line Straight Line
relationships
Crow’s Foot
Cardinality Indicators Defines the number of instances (1, N, M)
Notation
Shows hierarchy (e.g., Employee →
Generalization/Specialization Triangle
Manager, Worker)

Page 2 of 11
Database Systems LAB​ ​ SPRINIG 2025

4.2 Symbol Explanation with Examples

1.​ Entity (Rectangle): Represents objects like Student or Course.


2.​ Weak Entity (Double Rectangle): Depends on another entity (e.g., Project associated
with Course).
3.​ Attribute (Oval): Describes entity properties (e.g., Name, Email).
Page 3 of 11
Database Systems LAB​ ​ SPRINIG 2025

4.​ Multivalued Attribute (Double Oval): For attributes with multiple values (e.g., Phone
Numbers).
5.​ Derived Attribute (Dashed Oval): Computed attributes (e.g., Age from Date of Birth).
6.​ Relationship (Diamond): Shows associations (e.g., Enrolls connects Student and
Course).
7.​ Identifying Relationship (Double Diamond): Connects a weak entity to its owner.
8.​ Line (Straight Line): Links attributes and entities; dashed lines denote derived
attributes.
9.​ Cardinality Indicators (Crow’s Foot): Indicate multiplicities like 1:1, 1:N, M:N.
10.​Generalization/Specialization (Triangle): Demonstrates entity hierarchies.

5. Comprehensive Example: University Management System

This section provides a step-by-step example covering the entire ER modeling process, including
a full system-level diagram, SQL implementations, and corresponding table structures.

5.1 Problem Statement

"A university tracks students, courses, instructors, and departments. Students enroll in courses,
and each course is taught by an instructor. Departments offer courses, and students belong to
departments. Courses may have projects. The system keeps enrollment records, instructor
assignments, and departmental offerings."

5.2 Step 1: Identify Entities and Attributes

Entity Attributes
Student student_id (PK), name, email, date_of_birth
Course course_code (PK), title, credits
Instructor instructor_id (PK), name, email
Department dept_id (PK), name, location
Enrollment enrollment_id (PK), date_enrolled, grade
Project (Weak Entity) project_id (Partial Key), project_title

Note: "Enrollment" acts as a relationship entity capturing attributes like date_enrolled and
grade.

5.3 Step 2: Identify Relationships and Cardinalities

●​ Enrolls: Student ↔ Course (Many-to-Many)

Page 4 of 11
Database Systems LAB​ ​ SPRINIG 2025

●​ Teaches: Instructor ↔ Course (One-to-Many)


●​ Offers: Department ↔ Course (One-to-Many)
●​ Belongs_To: Student ↔ Department (Many-to-One)
●​ Has_Project: Course ↔ Project (One-to-Many)

5.4 Step 3: Full University Management System ER Diagram

Below is the full ER diagram, showcasing all entities, attributes, relationships, cardinalities, and
symbols.

Diagram Key and Element


Placement (Fig 1)

1.​ Rectangles: Regular entities

●​ Where in the diagram:

Page 5 of 11
Database Systems LAB​ ​ SPRINIG 2025

o​ Student (bottom left)


o​ Course (center)
o​ Instructor (bottom right)
o​ Department (top center)

2.​ Double octagons: Weak entities (Project)

●​ Where in the diagram:


o​ Project entity is on the right side of the Course entity, connected via the
Has_Project relationship.

3.​ Diamonds: Relationships

●​ Where in the diagram:


o​ Enrolls: Between Student and Course (center left)
o​ Teaches: Between Instructor and Course (bottom center-right)
o​ Offers: Between Department and Course (top center)
o​ Belongs_To: Between Student and Department (top left)
o​ Has_Project: Between Course and Project (center right)

4.​ Crow’s foot notation: Denotes cardinality (1:1, 1:N, M:N)

●​ Where in the diagram:


o​ M:N:
▪​ Between Student and Enrolls
▪​ Between Enrolls and Course
o​ 1:N:
▪​ Between Department and Offers → Course
▪​ Between Instructor and Teaches → Course
▪​ Between Course and Has_Project → Project
o​ M:1:
▪​ Between Student and Belongs_To → Department

5.​ Solid lines: Relationships between entities

●​ Where in the diagram:


o​ Connect all entities to their relationships (e.g., Student → Enrolls, Course →
Has_Project).
o​ No dashed lines currently exist, as no derived attributes are represented.

5.5 Step 4: Translating ER Diagram to Relational Schema with SQL and Table Structures

Below are the SQL commands with corresponding table representations to help students
visualize the created tables.

Page 6 of 11
Database Systems LAB​ ​ SPRINIG 2025

5.5.1 Creating Tables and Their Structures

CREATE TABLE Department (


dept_id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
location VARCHAR(100)
);

Department Table Structure:

dept_id (PK) name location


INT VARCHAR(50) VARCHAR(100)
CREATE TABLE Instructor (
instructor_id INT PRIMARY KEY,
name VARCHAR(50),
email VARCHAR(100)
);

Instructor Table Structure:

instructor_id (PK) Name email


INT VARCHAR(50) VARCHAR(100)
CREATE TABLE Course (
course_code VARCHAR(10) PRIMARY KEY,
title VARCHAR(100),
credits INT,
dept_id INT,
FOREIGN KEY (dept_id) REFERENCES Department(dept_id)
);

Course Table Structure:

course_code (PK) Title credits dept_id (FK)


VARCHAR(10) VARCHAR(100) INT INT
CREATE TABLE Student (
student_id INT PRIMARY KEY,
name VARCHAR(50),
email VARCHAR(100),
date_of_birth DATE,
dept_id INT,
FOREIGN KEY (dept_id) REFERENCES Department(dept_id)
);

Student Table Structure:

student_id (PK) Name email date_of_birth dept_id (FK)


INT VARCHAR(50) VARCHAR(100) DATE INT
CREATE TABLE Enrollment (

Page 7 of 11
Database Systems LAB​ ​ SPRINIG 2025

enrollment_id INT PRIMARY KEY,


student_id INT,
course_code VARCHAR(10),
date_enrolled DATE,
grade CHAR(2),
FOREIGN KEY (student_id) REFERENCES Student(student_id),
FOREIGN KEY (course_code) REFERENCES Course(course_code)
);

Enrollment Table Structure:

enrollment_id (PK) student_id (FK) course_code (FK) date_enrolled grade


INT INT VARCHAR(10) DATE CHAR(2)
CREATE TABLE Project (
project_id INT,
course_code VARCHAR(10),
project_title VARCHAR(100),
PRIMARY KEY (project_id, course_code),
FOREIGN KEY (course_code) REFERENCES Course(course_code)
);

Project Table Structure:

project_id (PK) course_code (PK, FK) project_title


INT VARCHAR(10) VARCHAR(100)

5.5.2 Inserting Sample Data

INSERT INTO Department VALUES (1, 'Computer Science', 'Building A'), (2,
'Mathematics', 'Building B');
INSERT INTO Instructor VALUES (101, 'Dr. Alice', '[email protected]'), (102, 'Dr.
Bob', '[email protected]');
INSERT INTO Course VALUES ('CSE101', 'Programming I', 3, 1), ('MTH201',
'Calculus', 4, 2);
INSERT INTO Student VALUES (1001, 'John Doe', '[email protected]', '2000-05-12', 1),
(1002, 'Jane Smith', '[email protected]', '1999-07-23', 2);
INSERT INTO Enrollment VALUES (1, 1001, 'CSE101', '2024-01-15', 'A'), (2, 1002,
'MTH201', '2024-01-17', 'B');
INSERT INTO Project VALUES (501, 'CSE101', 'Chatbot Development'), (502,
'MTH201', 'Statistics Report');

Department Table:

dept_id (PK) name location


1 Computer Science Building A
2 Mathematics Building B

Page 8 of 11
Database Systems LAB​ ​ SPRINIG 2025

Instructor Table:

instructor_id (PK) name email


101 Dr. Alice [email protected]
102 Dr. Bob [email protected]

Course Table:

course_code (PK) title credits dept_id (FK)


CSE101 Programming I 3 1
MTH201 Calculus 4 2

Student Table:

student_id (PK) name email date_of_birth dept_id (FK)


1001 John Doe [email protected] 2000-05-12 1
1002 Jane Smith [email protected] 1999-07-23 2

Enrollment Table:

enrollment_id (PK) student_id (FK) course_code (FK) date_enrolled grade


1 1001 CSE101 2024-01-15 A ​
2 1002 MTH201 2024-01-17 B Project
Table:

project_id (PK) course_code (PK, FK) project_title


501 CSE101 Chatbot Development
502 MTH201 Statistics Report

5.5.3 Querying Data

-- Retrieve all students enrolled in 'CSE101'


SELECT s.name, e.date_enrolled
FROM Student s JOIN Enrollment e ON s.student_id = e.student_id
WHERE e.course_code = 'CSE101';

Output:

name date_enrolled
John Doe 2024-01-15
-- Find instructors teaching more than one course
SELECT i.name, COUNT(*) AS course_count
FROM Instructor i JOIN Course c ON i.instructor_id = c.dept_id
GROUP BY i.name HAVING course_count > 1;

Page 9 of 11
Database Systems LAB​ ​ SPRINIG 2025

Output:

name course_count
(No results) (In this sample data, no instructor teaches more than one course)

Note: To see meaningful results, assign more courses to the same instructor in the data.

6. Exercises and Deliverables

Deliverables:

Students must:

1.​ Design an ER Diagram for a Hospital Management System (patients, doctors,


appointments, treatments) with SQL scripts and table structures.
2.​ Develop a Retail Store System ER Model (products, customers, orders, suppliers), with
sample data and visualized tables.
3.​ Populate Tables: Insert at least five records per entity.
4.​ Relationship Analysis: Submit cardinality and participation explanations.
5.​ Create a Banking System ER Model with complete SQL implementation and table
structures.

7. ER Diagram Symbols Reference Sheet (Cheatsheet)

Symbol Shape Description Use Case Example


Entity Rectangle Student, Course
Weak Entity Double Rectangle Project
Attribute Oval Name, Email
Multivalued Attribute Double Oval Phone Numbers
Derived Attribute Dashed Oval Age (from Date of Birth)
Relationship Diamond Enrolls, Teaches
Identifying Relationship Double Diamond Has_Project
Line Straight/Dashed Entity-Relationship connections
Cardinality Indicators Crow’s Foot Notation 1:1, 1:N, M:N relationships
Generalization/Specialization Triangle Employee → Manager, Worker

Use the cheatsheet while designing to avoid confusion. Ensure proper use of primary and foreign
keys, and validate relationships through sample data queries. Always review the resulting tables
to understand how the ER model translates into a functional database.

Page 10 of 11
Database Systems LAB​ ​ SPRINIG 2025

Page 11 of 11

You might also like