0% found this document useful (0 votes)
29 views70 pages

NI_DBMS_ER Model 2024

Uploaded by

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

NI_DBMS_ER Model 2024

Uploaded by

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

Database Design

Entity-Relationship Modeling

N. Ilayaraja
PSG Tech.

1
Introduction
 A data model is an integrated collection of concepts that represents real
world objects, events, and their relationships
– There are two types of data models:
 Object-based data models ( ER Model, Object-oriented model )
 Relation-based data models (Relational Model, Network Model, Hierarchical
Model)

– In database design, we develop an object-based model first


 Entity-relationship model
 Object-oriented model

– Then systematically convert the object based model into a relation-based


model
 More suitable for database implementation

2
Types of Data Models

Entity Relationship Model


Object Oriented Model

Relational Data Model Hierarchical Data Model

Network Data Model

3
The Entity-Relationship Model
 An entity-relationship model describes data in terms of the following:
– Entities
– Relationship between entities
– Attributes of entities

 Graphically display an E-R model using an entity-relationship diagram


(E-R diagram)
 ER-diagrams are a formalism to model real-world scenarios
 There are many versions of ER-diagrams that differ both in their
appearance and in their meaning (Peter Chen & Crow foot Notations)

4
What is it about?
 ER model is used to show the Conceptual schema of an organisation.

 Independent of specific data model or DBMS


 The model is later transformed into a Logical model (e.g. relational) on
which the physical database is built

 An ER model is typically drawn at up to three levels of abstraction:


Conceptual ERD / Conceptual data model
Logical ERD / Logical data model
Physical ERD / Physical data model

5
Entity Relationship Model at levels
of Abstraction
Conceptual data model
• Conceptual ERD models the business objects that should exist in a system and
the relationships between them. A conceptual model is developed to present an
overall picture of the system by recognizing the business objects involved. It
defines what entities exist.
Logical data model

• Logical ERD is a detailed version of a Conceptual ERD. A logical ER model is


developed to enrich a conceptual model by defining explicitly the columns in
each entity and introducing operational and transactional entities.
Physical data model

• Physical ERD represents the actual design blueprint of a relational database. A


physical data model elaborates on the logical data model by assigning each
column with type, length, nullable, etc.
Entity
 An entity is an object that exists in the world and which is distinguishable
from other objects
– Can be a person, a place, an object, an event, or a concept

– Examples:
 Person: Student, Employee, Client
 Object: Couch, Airplane, Machine
 Place: City, Park, Room, Warehouse
 Event: War, Marriage, Lease
 Concept: Project, Account, Course

Entity Representation in an E-R Diagram

10
Entities
 Entity - distinguishable “thing” in the real world

– Strong (or regular) entity - entities have an independent


existence (e.g. staff)
– Weak entity - existence dependent on some other entity
(children/family members of employee)

E n tity Na m e Entity type name


(singular, no spaces,
capital letter at start of each word)

space for attributes


12
Entity (cont.)
 An entity type defines a collection of entities that have the same
attributes

 An entity instance is a single item in this collection

 An entity set is a set of entity instances which all are sharing the
common properties/attributes ( not attributes values).

 Example:
– Entity type: STUDENT
– Entity instance: Student with ID number 24MX101, Name ABI
– Entity set: Collection of all students

13
Attributes
 An attribute is a property or characteristic of an entity type
– We represent an entity with a set of attributes
– Used to describe entities

– Examples:
 STUDENT = {Student ID, SSN, Name, Address, Phone, Email, DOB}
 ORDER = {Order ID, Date of Order, Amount of Order}
 ACCOUNT = {Account Nr, Account type, Balance}
 CITY = {Name, State, Population}

– Attributes Types:
 Simple, composite, single-valued, multi-valued, stored, and derived

14
Attributes

 Entity types have Attributes (or properties) which associate each


entity with a value from a domain of values for that attribute

 Attributes can be
– simple (atomic) e.g. Surname; date of birth
– Composite e.g. address (street, town, postcode)
– Multi-valued e.g. phone number
– Complex nested multi-valued and composite
– Base or Derived e.g. DOB is a Base; age is a derived
– Key e.g. Rollno, EmpId; Foreign Key
Attributes in E-R Diagram

Attributes of the STUDENT Entity Type

16
Attributes in E-R Diagram

birthday
id
ACTOR

name address

Attributes of the ACTOR Entity Type

17
Another Option for a Key?

birthday
id
Actor

name address

18
Simple and Composite Attributes
 A simple or an atomic attribute cannot be further divided into smaller
components
– Examples:
 City
 State

 A composite attribute, however, can be divided into smaller subparts


where each subpart represents an independent attribute
– Examples:
 Name: First Name, Last Name
 Address: Street, City, State, Zip

19
Single-Valued and Multi-Valued Attributes
 Single-valued attributes have a single value for an entity instance
– Examples:
 Major
 Date Of Birth

 Multi-valued attributes, on the other hand, may have more than one
value for an entity instance
– Denoted with a double-lined ellipse

– Example:
 Languages: Stores the names of the languages that a student speaks

21
Stored and Derived Attributes
 The value of a derived attribute can be determined by analyzing other
attributes
– Therefore, no need to store them in the database directly

– Denoted with a dashed ellipse


– May be calculated and stored latter by using existing attributes or formula

– Example:
 Age: Can derived from the current date and the attribute DateOfBirth

 An attribute whose value cannot be derived from the values of other


attributes is called a stored attribute

24
Key Attribute
 A key attribute (or identifier) is a single attribute or a combination of
attributes that uniquely identify an individual instance of an entity type
– Underlined in an E-R diagram

– Example:
 Student: StudentID

The Key Attribute

26
Candidate Key Attribute
 Sometimes no single attribute can uniquely identify an instance of an
entity type

 A composite key is a composite attribute that uniquely identifies each


entity instance

– Example:
 City: {Name, State}

The Composite Key Attribute

27
Relationships
 A relationship is an association / binding / links / bonds among several
entities ( entity types)
 Examples:
– STUDENT “takes” COURSES
– CUSTOMER “has” ACCOUNT
– CUSTOMER “books” TICKET
– FACULTY “assign to “ CABIN
 Represented by diamond shaped box connected to relating entities

Relationship between CUSTOMER and ACCOUNT Entities

Relationship Set: Set of similar relationships

28
Overview – Part 1
 3.1 Introduction
 3.2 The Entity-Relationship Model
 3.3 Entity
 3.4 Attributes
 3.5 Relationships
 3.6 Degree of a Relationship
 3.7 Cardinality of a Relationship
 3.8 Unary Relationship
 3.9 Binary Relationship
 3.10 Ternary Relationships
 3.11 Attributes of Relationships
 3.12 Associative Entities
 3.13 Weak Entity Types

29
Degree of a Relationship
 The number of entity sets that participate in a relationship is called the
degree of relationship

 Three common degrees in a database:


– Unary (degree 1)
 An association between two instances of the same entity type
 R є E1 x E1

– Binary (degree 2)
 An association between two instances of two different types
 R є E1 x E2

– Ternary (degree 3)
 An association between three instances of three different types
 R є E1 x E2 x E3

30
Cardinality of a Relationship
 Maximum cardinality represents the maximum number of instances of
entity B that can be associated with any instance of entity A

The Four Types of Relationships between Entity Types

31
Maximum Cardinality
 Relationship types by maximum cardinality:
– One-to-One
– One-to-Many (and vice-versa)
– Many-to-Many

One Many

Relationship Types Based on Maximum Cardinality

32
Minimum Cardinality
 The minimum cardinality of a relationship is defined as the minimum
number of instances of entity B that must be associated with each
instance of entity A

Optional

Mandatory

Relationship Types Based on Minimum Cardinality

33
Unary Relationships - Examples

One-to-One

One-to-One

Many-to-Many

34
Recursive Unary Relationships

• An entity set can participate more than once in a


relationship
• In this case, we add a description of the role to the ER-
diagram

phone
number
manager

id
Employee Manages
worker
name

address

35
Binary Relationships - Examples

One-to-One

One-to-Many

Many-to-Many

36
Example

title
birthday

id
Actor Acted In Film year

name

address type

Where does the salary salary


attribute belong?
37
Mandatory minimum cardinalities

38
Ternary Relationships - Examples

Musical Performance
Example

Student “Uses”
Equipment for a
Project Example

39
Ternary Relationships - Examples

id Director name

id
Actor Produced Film title

name

40
Ternary relationships

Note: a relationship can have attributes of its own


Key Constraints
 Key constraints specify whether an entity can participate in
one, or more than one, relationships in a relationship set
 When there is no key constraint an entity can participate any
number of times
 When there is a key constraint, the entity can participate at
most one time
 Key constraints are drawn using an arrow from the entity set
to the relationship set

42
One-to-Many
 A film is directed by at most one director
 A director can direct any number of films

id
Director Directed Film title

name

Director Directed Film


43
Many-to-Many
 A film is directed by any number of directors
 A director can direct any number of films

id
Director Directed Film title

name

Director Directed Film


44
One-to-One
 A film is directed by at most one director
 A director can direct at most one film

id
Director Directed Film title

name

Director Directed Film


45
Relationship Instance is
between specific entity
instances
46
Relationship Sets
 An attribute can also be property of a relationship set.
Optional cardinalities with unary degree, one-to-one relationship
A unary relationship with an attribute. This has a many-to-many
relationship

Representing a bill-of -materials structure


Examples of multiple relationships – entities can be related to
one another in more than one way
Professors and courses (fixed upon constraint)

Here,max
cardinality
constraint is 4
Attributes of Relationships
 An attribute on a relationship stores information related to the
relationship is known as “Descriptive Attribute”
– Much like attributes on entity types

Relationship
Attribute

Example of an Attribute of a Relationship

52
Associative Entities
 An entity–has attributes

A relationship–links entities together
 When should a relationship with attributes instead be
an associative entity?
– All relationships for the associative entity should be many
– The associative entity could have meaning independent of the other
entities
– The associative entity preferably has a unique identifier, and should
also have other attributes
– The associative entity may participate in other relationships other
than the entities of the associated relationship
– Ternary relationships should be converted to associative entities

53
Associative Entities
 An associative entity is an entity type that connects the instances of
one or more entity types and contains attributes particular to this
association
– Allows us to store data from relationship attributes more effectively

 Relationship meets one of the following conditions:


– It is a many-to-many binary relationship
– It is a ternary relationship or a relationship of an even higher degree

54
A binary relationship with an attribute

Here, the date completed attribute pertains specifically to


the employee’s completion of a course…it is an attribute
of the relationship

55
An associative entity (CERTIFICATE)

Associative entity is like a relationship with an attribute, but it is


also considered to be an entity in its own right.

Note that the many-to-many cardinality between entities in above


has been replaced by two one-to-many relationships with the
associative entity.

56
Associative Entities – Example 1

Many-to-Many Binary Relationship

Many-to-Many Binary Relationship Converted to an Associated Entity

57
Associative Entities – Example 2

Ternary Relationship

Ternary Relationship Converted to an Associated Entity


58
Weak Entity Types
 A strong entity type exists independent of other entity types

 A weak entity type depends on another entity type

 Entity type depends on the identifying owner

Weak
Entity

Weak Entity in an E-R Diagram

59
Strong vs. Weak Entities, and
Identifying Relationships
Strong entities:
•exist independently of other types of entities
•has its own unique identifier
•identifier underlined with single-line
Weak entity:
•dependent on a strong entity (identifying owner)…cannot exist
on its own
•does not have a unique identifier (only a partial identifier)
•Partial identifier underlined with double-line
•Entity box has double line
Identifying relationship:
•links strong entities to weak entities

60
Identifying relationship

Strong entity Weak entity

61
Strong entity Identifying relationship Weak entity

62
Existence Dependencies

 If the existence of entity x depends on the existence of


entity y, then x is said to be existence dependent on y.
– y is a dominant entity (in example below, loan)
– x is a subordinate entity (in example below, payment)

loan loan-payment payment

If a loan entity is deleted, then all its associated payment


entities must be deleted also.
Weak Entity Primary Key

 The discriminator (or partial key) of a weak entity set is the set of
attributes that distinguishes among all the entities of a weak entity set.

 The primary key of a weak entity set is formed by the primary key of the
strong entity set on which the weak entity set is existence dependent,
plus the weak entity set’s discriminator.

64
Weak Entity Sets
 We depict a weak entity set by double rectangles.
 We underline the discriminator of a weak entity set with a
dashed line.
 payment-number – discriminator of the payment entity set
 Primary key for payment – (loan-number, payment-
number)
Weak Entity

66
Example 1
A publishing company produces scientific books on various subjects. The
books are written by authors who specialize in one particular subject. The
company employs editors who, not necessarily being specialists in a
particular area, each take sole responsibility for editing one or more
publications.
A publication covers essentially one of the specialist subjects and is
normally written by a single author. When writing a particular book, each
author works with on editor, but may submit another work for publication to
be supervised by other editors. To improve their competitiveness, the
company tries to employ a variety of authors, more than one author being a
specialist in a particular subject.
Example 1 - answer

concerns edited by
Subject Publication

is specialised in
is written by
Editor

Author
Author-
works with Editor employs
Example 2
A General Hospital consists of a number of specialized wards (such as
Maternity, Paediatry, Oncology, etc). Each ward hosts a number of patients,
who were admitted on the recommendation of their own GP and confirmed
by a consultant employed by the Hospital. On admission, the personal
details of every patient are recorded. A separate register is to be held to
store the information of the tests undertaken and the results of a prescribed
treatment.

A number of tests may be conducted for each patient. Each patient is


assigned to one leading consultant but may be examined by another doctor,
if required. Doctors are specialists in some branch of medicine and may be
leading consultants for a number of patients, not necessarily from the same
ward.
Example 2 – Full answer
sp ecialised in
Ward Specialty

g iv es Tests

is ad mitted to
Test-Results sp ecialised in
Treatment
fo llo w s d ev is es
g ets

is d iag n o sed d iag n o ses


Patient Diagnosis Doctor

reco mmen d s
as sig n ed to
0
GP
Consultant

You might also like