Week 03 - Data Models and ER Model
Week 03 - Data Models and ER Model
Week 03
Data Models
and ER Diagram Model
Engr. Rashid Farid Chishti
http://youtube.com/rfchishti
http://sites.google.com/site/chis
hti International Islamic University H-10, Islamabad, Pakistan
Learning Objectives
Understand different types of data models
Learn the components and uses of the Entity-Relationship (ER) model
Develop ER diagrams with entities, attributes, and relationships
Grasp the concept of cardinality and mapping constraints
What is a Data Model ?
Data Model gives us an idea that how the final system will look like after its
complete implementation.
It defines the data elements and the relationships between the data elements.
Data Models are used to show how data is stored, connected, accessed and
updated in the database management system.
Here, we use a set of symbols and text to represent the information so that
members of the organization can communicate and understand it.
Though there are many data models being used nowadays but the Relational
model is the most widely used model.
Types of Data Models
Model Best For Example
Hierarchical Simple parent-child relationships File systems
Network Complex many-to-many relationships Telecom databases
ER Model Database design and planning Conceptual schema
Relational Structured data with relations Banking systems, ERP
Object-Oriented Multimedia, CAD Video games, simulations
Document-Oriented
Unstructured, dynamic schema Web apps, IoT
(NoSQL)
Key-Value (NoSQL) Fast lookups Caching, real-time analytics
Columnar (NoSQL) Large-scale analytics Data warehouses
Social networks, fraud
Graph (NoSQL) Complex relationship modeling
detection
Hierarchical Model
Hierarchical Model was the first DBMS model.
This model organizes the data in the hierarchical tree structure.
The hierarchy starts from the root which has root data and then it expands in
the form of a tree adding child node to the parent node.
College
A parent record can have multiple child records,
but a child record cannot have more than one parent. Department Infrastructure
Examples
IBM Information Management System (IMS) Course Teachers Students
Windows Registry
XML Databases Theory
Traditional file systems (e.g., NTFS, ext4)
Lab
Network Model
This model is an extension of the hierarchical model.
Data is organized as a graph, where records (nodes) can have multiple parent
and child records. It was the most popular model before the relational model.
This model is the same as the hierarchical model, the only difference is that a
record can have more than one parent.
The model was popular in the 1960s and 1970s
Features of Network Model
Ability to Merge more Relationships,
Many paths & Circular Linked List
Examples
Integrated Database Management System (IDMS)
CODASYL DBMS, Raima Database Manager.
Object Oriented Model
The real-world problems are more closely represented through the object-
oriented data model.
In this model, both the data and relationship are present in a single structure
known as an object.
We can store audio, video, images, etc in the database which was not possible
in the Relational Model.
In this model, two are more objects
are connected through links.
We use this link to relate one
object to other objects.
Examples:
MongoDB, CouchDB, ObjectDB
NoSQL Model
The NoSQL Model refers to a category of database management systems that are designed
to handle unstructured, semi-structured, or structured data in a flexible and scalable way.
Unlike traditional relational databases, which use tables and SQL (Structured Query
Language), NoSQL databases use a variety of data models to store and manage data.
NoSQL databases are particularly well-suited for modern applications that require high
scalability, flexibility, and performance, such as web applications, big data, and real-time
analytics.
Types of NoSQL Data Models:
Document-Oriented Model
Key-Value Model
Graph Model
Document-Oriented Model
Description: Stores data as documents, typically in JSON, BSON, or XML
format.
Structure: Each document is a self-contained unit with key-value pairs, nested
objects, or arrays.
Use Cases:
Content management systems (CMS).
E-commerce applications.
Real-time analytics.
Examples:
MongoDB: A popular document-oriented database.
Relationships: Links between entities, how entities interact with each other
Type Name
Date Type Amount
Multi Valued: Can have more than one value for a single entity.
Examples: Phone Numbers for a person. Degrees of a professor.
Key Attribute Non-key Attribute Week Attribute Derived Attribute Multi Valued
Attribute
Study Study
History
Strong Identifying
Relationship Relationship
ER Diagram Symbols
Composite Attribute
DoB Name
Roll Student
Number Hobbies
Single Valued
Attribute Multi Valued
Attribute Age DoB Age
Derived Attribute
ER Diagram with Different Types of Attributes
Week Entity
Strong Entity
Phone patient Study
has Insurance
Number
Identifying
Multi Valued Attribute Relationship
insurance id
Key Attribute
Age
provider
patient id mr no DoB Derived Attribute
Simple Attribute
Key Attribute Simple Attribute
coverage
year month day
details
Composite Attribute
Multi Valued Attribute
Keys Example
name age name
grade
The value of candidate key can never be NULL. ID RollNo Name Email
It is possible to have multiple candidate keys 1 1 Rashid [email protected]
in a relation.
2 2 Ibrahim [email protected]
3 3 Bilal [email protected]
4 Ahmed [email protected]
Candidate Key
Products Orders
Primary Key
Types of Keys
Student Table Course Table
Student_ID Name Age Major Course_ID Course_Name Instructor
101 Alice 22 CS CS101 Databases Dr. Smith
102 Bob 24 Math MT202 Algebra Dr. Lee
103 John 23 CS
Enrollment Table
(Relationship Table)
Primary Key: Student_ID, Uniquely identifies each student Student_ID Course_ID Grade
in Student Table. 101 CS101 A
Candidate Key: Email, Can also uniquely identify students. 102 MT202 B+
Foreign Key (in another table):
Course_ID in an Enrollment table, referencing Course_ID in the Course table.
Student_ID in an Enrollment table, referencing Student_ID in the Student table.
Composite Key: A key that consists of two or more columns to uniquely identify a record
when a single column is insufficient for unique identification. (Student_ID, Course_ID) in
Enrolment table.
Relationship
It describes associations between entities. Symbol for Relationships
Can have descriptive attributes (relationship attributes)
Relationship
It is represented by a diamond or rhombus shape.
Naming:
Student and Course have Enroll relationship, Course
Since
teacher teaches Student Teacher
Department
Types of Relationship
Binary Relationship
It is a relationship between exactly two entity types.
It represents how two entities are associated with each other within a database.
Ternary Relationship
It is a relationship that involves three different entity types.
Sometimes, breaking a ternary relationship into multiple binary relationships can lead
This loses important information! It doesn't clearly specify which supplier supplied
Example: "Person" - (owns) - "Passport ".Each person owns only one passport, and each
1 employs M
Department Employee
Cardinality Constraints
Many-to-One Relationship
When more than one instance of an entity on the right and only one instance of the
Amount Room
Date Delivery Number
Semester Total
Status Students
Identifying Relationship
Recursive or a Unary Relationship
An Entity Type linked with itself, is called recursive or unary relationship
Example Roommate, where STUDENT is linked with STUDENT
M has
Course pre-req
N
1 is a
1 Is Person parent of
Student roommate
M
M
1 has
Project sub project
M
1 1 is a
Employee Manages Person friend of
M M
Cardinality in Relationships
Definition: Defines the number of instances of
one entity that can be associated with another.
Types:
One-to-One (1:1): One entity relates to one entity (e.g., Country - Capital)
One-to-Many (1:M): One entity relates to many (e.g., Student - Books)
Many-to-Many (M:M): Many entities relate to many (e.g., Students - Courses)
1 has 1 1 M Student
Country Capital Student borrow Book
M
1 drives 1 Custome M orders M
Driver Truck Item
r
enroll
M enroll 1
Player Team
M
Employe M M M M
assigned Project Teacher teach Course
e
Cardinality in Relationships
Employee Department
51
Since
56
works Location
3/3/93 60
Department 123
2/2/92
145
3/1/92
ISB
147
3/1/92
LHR
147
Works in KAR
Employee
Location
Cardinality Notations
One:
Origin entity has a one association with the target entity.
Many:
A Target entity can be related to the origin many times
One and Only One:
The origin entity has only one target entity associated with it
One entity is required for the existence of the other.
Zero to One:
The origin entity can either have no associated entities or up to one target entity
associated with it.
Notations that begin with zero generally indicate that the relationship is optional
Cardinality Notations
One or Many:
The origin entity can have one or many linked Target entities associated with it
Zero to Many:
The target entity can be associated with the origin entity any number of times from zero
on up this is another optional relationship
Roles in Relationships
Advisee Advisor M provides is supplied N Product
Student supervises
Advises Teacher Supplier buys
supervises
products by a supplier
Roles: Many customers can buy buys
Advisor A teacher who advises students. many products from many products Price
Advisee A student receiving advice. M
suppliers, at different prices
Customer
manager
Employee supervises
reports to