0% found this document useful (0 votes)
18 views40 pages

Conceptual Design

Uploaded by

razaehaider62
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)
18 views40 pages

Conceptual Design

Uploaded by

razaehaider62
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/ 40

CSC.

222 - Database Systems


Lecture 6 - Data Modelling Using the Entity-Relationship Model
(Conceptual Design)

Prof. Dr. Muhammad Saleem Vighio

Department of Computer Science,


Quaid-e-Awam University, Nawabshah.

May 13, 2024

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 1 / 40


Lecture Outline
Overview of Database Design Process
Entity Relationship Model
Example Database Application (COMPANY)
ER Diagrams - Notation
ER Model Concepts
I Entities and Entity Types
I Attributes and Keys
I Relationships and Relationship Types
Degree of Relationship Types
Constraints on Relationship Types
Data modelling tools
Exercises

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 2 / 40


Overview of Database Design Process

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 3 / 40


Overview of Database Design Process

Requirements collection and analysis: During this step, the


database designers interview prospective database users to understand
and document their data and functional (or operational) requirements.

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 4 / 40


Overview of Database Design Process

Conceptual design: In this step collected requirements are concisely


represented using ER diagram. The ER diagram includes detailed
descriptions of the entity types, relationships, and constraints.
Because these concepts do not include implementation details, they
are usually easier to understand and can be used to communicate
with non-technical users.

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 5 / 40


Overview of Database Design Process

Logical design: Logical design is the actual implementation of the


database, using a commercial DBMS like SQL server. In relational
DBMS, entities are represented as tables and using constraints like
primary and foreign keys entities are associated.

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 6 / 40


Overview of Database Design Process

Physical design: In this phase, details regarding how data is stored


in the computer are specified. It specifies details about the internal
storage structures, file organizations, indexes, access paths, and
physical design parameters for the database files.

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 7 / 40


Entity-Relationship Model

The entity relationship (ER) data model has existed for over 55 years
when Peter Chen proposed ER Diagrams in 1971 to create a uniform
convention that can be used as a conceptual modeling tool.
ER modelling is based on three concepts:
I Entities: Objects or things in the real-world, e.g., student, course,
section, etc.
I Attributes: characteristics or properties of entities, e.g., roll no, class,
and age of student entity
I Relationships: dependency or association between entities, e.g., follows
is a relationship between student and course in a learning environment

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 8 / 40


The BIG Picture: ER Model of Company

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 9 / 40


ER Diagram Notations

Entity
Attribute Attribute Attribute Attribute

Weak Entity
Attribute
Key Attribute

Composite
Attribute

Relationship Multi-valued
Attribute

Identifying
Relationship Derived Attribute

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 10 / 40


Entities

Entities are specific objects or things in the mini-world that are


represented in the database.
I For example the EMPLOYEE John Smith, the Research
DEPARTMENT, the ProductX PROJECT
In ER diagram, entities are represented in rectangles
I EMPLOYEE

EMPLOYEE

I DEPARTMENT

DEPARTMENT

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 11 / 40


Entities
An entity set is a set of entities of the same type.
I For example set of all EMPLOYEES, DEPARTMENTS, PROJECTS
An entity type describes the entity set.
I EMPLOYEE is an entity type with attributes: name, ssn, address, etc.

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 12 / 40


Entities

Weak entity: an entity that does not have its own primary key and
depends on the primary key of other entities (identifying owners) with
which it is associated.
Identifying relationship: a relationship between the weak entity and
the identifying owner.
Partial key: attributes that uniquely identify entities within the
identifying relationship.
In ER diagram, weak entity is denoted as double rectangle:

DEPENDENT

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 13 / 40


Attributes
Attributes are properties used to describe an entity.
I For example an EMPLOYEE entity may have the attributes Name,
SSN, Address, Gender, BirthDate
Attributes are represented in ellipses
Single valued versus multi-valued
I e.g., single versus multiple addresses

EMPLOYEE adress EMPLOYEE adress

Simple versus structured (or composite) attributes

street

EMPLOYEE adress city

state

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 14 / 40


Attributes, cont.
Stored versus derived
I e.g., an age can be derived from a stored birth-date

BirthDate

EMPLOYEE

Age

Null versus non-null


I e.g., email address and SSN
Keys
I Uniquely identifies an entity within an entity set

EMPLOYEE SSN

Domain constrained
I e.g., SSN number must be exactly 10 decimal digits
Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 15 / 40
Relationships

The association among entities is called a relationship. In other


words, a relationship relates two or more distinct entities with a
specific meaning.
I For example, EMPLOYEE John Smith WORKS ON the ProductX
PROJECT, or EMPLOYEE Franklin Wong MANAGES the Research
DEPARTMENT.

EMPLOYEE WORKS_ON PROJECT

MANAGES

PROJECT

I Relationships are represented as diamond.

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 16 / 40


Relationships

Relationships of the same type are grouped or typed into a


relationship type.
I For example, the WORKS FOR relationship type in which EMPLOYEEs
and DEPARTEMENTs participate, or the MANAGES relationship type
in which EMPLOYEEs and DEPARTMENTs participate.

EMPLOYEE DEPARTMENT

John Smith Research

Franklin Wong WORKS_FOR Administration

Ann Joy Headquarters

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 17 / 40


Relationships
EMPLOYEE DEPARTMENT

John Smith Research

Franklin Wong WORKS_FOR Administration

Ann Joy Headquarters

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 18 / 40


Degree of Relationship Type

The number of participating entities in a relationship defines the


degree of the relationship.

I Unary (or recursive) - degree 1.


I Binary - degree 2.
I Ternary - degree 3.
I n-ary - degree n.

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 19 / 40


Degree of Relationship Type

Unary (or recursive) - Unary relationship is a relationship type where


the same entity type participates more than once in a different role.
I Example:

Course

Requires

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 20 / 40


Degree of Relationship Type (Unary) - Company
Company database - employees supervise other employee

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 21 / 40


Degree of Relationship Type

Binary - Relationships of degree two (2 entity types) are binary.


I Example:

Student Learn Course

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 22 / 40


Degree of Relationship Type

Ternary - A relationship of degree three (3 entity types) are ternary.


I Example: registration of a student in a course by a staff

Student Register Course

Staff

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 23 / 40


Degree of Relationship Type

N-ary - In the N-ary relationship, there are n types of entity that


associates. An an N-ary relationship exists when there are n types of
entities involved in it.

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 24 / 40


Constraints on Relationships

Constraints on Relationship Types (aka ratio constraints) are of two


types:

1 Cardinality ratio (also called maximum cardinality)


F One-to-one (1:1)
F One-to-many (1:N) or Many-to-one (N:1)
F Many-to-many
2 Participation constraint (also called minimum cardinality or existence
dependency constraints)
F partial (or optional) participation (zero, not existence-dependent)
F total (one or more, mandatory, existence-dependent)

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 25 / 40


Constraints on Relationships - Cardinality ratio

One-to-One relationship (1:1)

A professor chairs at most one department; and a department is chaired by


only one professor.

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 26 / 40


Constraints on Relationships - Cardinality ratio
One-to-Many relationship (1:M)

A course is taught by at most one professor; a professor teaches many


courses.
Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 27 / 40
Constraints on Relationships - Cardinality ratio

Many-to-One relationship (M:1)

A class requires one room; while a room can be scheduled for many classes.

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 28 / 40


Constraints on Relationships - Cardinality ratio
Many-to-Many relationship (M:N)

Many teachers teach many students.

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 29 / 40


Constraints on Relationships - Cardinality ratio - Summary

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 30 / 40


Constraints on Relationships - Participation constraint
Participation constraint: specifies whether the existence of an entity e
∈ E depends on being related to another entity via the relationship
type R.
I Partial participation: default; each entity e ∈ E can participate in a
relationship.
I Total participation: each entity e ∈ E must participate in a
relationship, it cannot exist without that participation (total
participation aka existence dependency).

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 31 / 40


Constraints on Relationships - Participation constraint

In ER Diagrams:
I partial participation is denoted by single line cardinality ratios are
mentioned as labels of edges (more precise cardinality limits can be
associated with relationship types)

I total participation is denoted by double line

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 32 / 40


Constraints on Relationships

Frequently used cardinalities and notations:

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 33 / 40


Exercises

Exercise # 1: Design an ER diagram based on the entities and


relationships given below. Also identify degree and cardinality ratio of each
relation:
Entities
I Customer(cust id, cust name, cust address(city, street, house nr.)),
I LandLineConnection(landline no, conn id, cust id, status),
I InternetConnection(conn id, ip address, speed),
I MobileConnection(company, packages),
I SimCard(sim nr, capacity)
Relationships
I applies for () : Customer and LandLineConnection
I Owns () : Customer and MobileConnection
I register for () : Customer and InternetConnection
I has() : MobileConnection and SimCard

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 34 / 40


Exercises

Exercise # 2: Design an ER diagram based on the entities and


relationships given below. Also identify degree and cardinality ratio of each
relation:
Entities
I TEACHER (TId, TName, TAddress),
I STUDENT (SId, SName, CId),
I COURSE (MATH, DBMS, ENG), CLASS (CId, CName),
I DEPARTMENT (DId, DName)
Relationships
I TEACHES (),
I LEARNS (),
I BELONGS TO (),
I WORKS FOR ()

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 35 / 40


Data Modelling Tools

UML (Unified Modelling Language)

Draw – https://app.diagrams.net/

Visio

ERDPlus – https://erdplus.com/

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 36 / 40


Exercises

Exercise # 3: Write requirements specification for the following


“examination schedule” database:

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 37 / 40


Exercises

Exercise # 4: Design ER digram for the following “Bank” database. Also


identify degree and constraints of each relationship type:

The Bank maintains information about Customers, Staff, Accounts, Loans


and Braches. The Bank has many branches in different cities and each
branch maintains information about Staff, Customers, Accounts and Loans
separately. Staff manages Accounts and Customers information whereas
each Customer has only one Account in that Bank. Customers borrow
Loans such that there are different types of Loans offered by the Bank.

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 38 / 40


Exercises

Exercise # 5: Design ER digram for the “Hospital” database given below.


Also identify degree and constraints of each relationship type and give
suitable attributes to each entity:

Hospital manages records of Doctors and Patients. Each Doctor treats


several Patients admitted in the Ward. On admission, each Patient is
assigned a particular Ward and each Ward has a particular number of Beds
in it. On discharge, every Patient pays Bills of treatment and medicine
incurred on treatment.

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 39 / 40


References

Ramez Elmasri, Shamkant Navathe; “Fundamentals of Database


Systems”, 6th Ed., Pearson, 2014.

Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish ;


“Database Modelling & Design - LOGICAL DESIGN”, 5th Ed., 2011.

GeeksforGeeks; “Structural Constraints of Relationships in ER


Model”, url: https://www.geeksforgeeks.org/structural-constraints-
of-relationships-in-er-model/

Prof. Dr. Muhammad Saleem Vighio CSC.222 - Database Systems 40 / 40

You might also like