0% found this document useful (0 votes)
10 views35 pages

4.BIT2103 - 4-The Entity-Relationship Model

Uploaded by

birungiderick887
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)
10 views35 pages

4.BIT2103 - 4-The Entity-Relationship Model

Uploaded by

birungiderick887
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/ 35

BIT2103 - Database Management Systems

CHAPTER 3
The Entity—Relationship
Model

Bachelor of Information Technology


The Entity-Relationship (E-R) model belongs to the first classification.

Data can be perceived as real world objects called entities and the relationships that
exist between them.

For example, in an organization, both employee and department are real world
objects. An employee belongs to a department.
Z1

Thus, the relation 'belongs to' links an employee to a particular department. The
employee-department relation can be modeled as shown in the following figure:
The Entity-Relationship (E-R) Model 2-11
The Entity-Relationship (E-R) Model 4-11

Binary Relationships The relationship can be seen in


> Relationships that exist between entities of two following figure:
different entity sets are called binary relationships.
> For example, an employee belongs to a department.
> The employee entity belongs to an employee entity
set. The department entity belongs to a department
entity set.
>

The relationship can be seen in


Ternary Relationships following figure:
> Relationships that exist between three entities of Employee Entity Set Department Entity Set

different entity sets are called ternary relationships.


> For example, an employee works in the accounts
department at the regional branch.
> The relation, 'works' exists between all three, the
employee, the department, and the location.

Location Entity Set
The Entity-Relationship (E-R) Model 5
11___________________________________
6
__

> Relationships can also be classified as per mapping cardinalities as follows:


> This kind of mapping exists when an entity of one entity set can be associated with
only one entity of another set.
> For example, every vehicle has a unique registration.
> No two vehicles can have the same registration details.
> The relation is one-to-one, that is, one vehicle-one registration.
> The mapping cardinality can be seen in the following figure:
The
The
Entity-Relationship
Entity-Relationship
(E-R)
(E-R)
Model
Model
66 XJ
MG
I
J

11

This kind of mapping exists when an entity of one set can be associated with more
> than one entity of another entity set.
For example, a customer can have more than one vehicle.
> Therefore, the mapping is a one to many mapping, that is, one customer - one or
> more vehicles.
The mapping cardinality can be seen in the following figure:
>
The Entity-Relationship (E-R) Model
10-11
11

Weak Entity Sets

> Entity sets that do not have enough attributes to establish a primary key are called
weak entity sets.

Strong Entity Sets

> Entity sets that have enough attributes to establish a primary key are called strong
entity sets.
> Consider the scenario of an educational institution where at the end of each
semester, students are required to complete and submit a set of assignments.
> The teacher keeps track of the assignments submitted by the students.
> An assignment and a student can be considered as two separate entities.
> The assignment entity is described by the attributes assignment_number and
subject.
> The student entity is described by roll_number, name, and semester.
> The assignment entities can be grouped to form an assignment entity set and the
student entities can be grouped to form a student entity set.
> The entity sets are associated by the relation 'submitted by
The Entity-Relationship (E-R) Model 11-11
UNIVERSITY

> The relationship is depicted in the following figure :


IIMX4

12

Attributes Attributes
■ assignment_number ■ roll_number
■ subject ■ name
■ semester

> The attributes, assignment_number and subject, are not enough to identify an
assignment entity uniquely.
> The roll_number attribute alone is enough to uniquely identify any student entity.
Therefore, roll_number is a primary key for the student entity set.
> The assignment entity set is a weak entity set since it lacks a primary key.
> The student entity set is a strong entity set due to the presence of the roll_number
attribute.
Entity-Relationship Diagrams 1-7
13 > The E-R diagram is a graphical representation of the E-R model.
> The E-R diagram, with the help of various symbols, effectively represents various
components of the E-R model.
> The symbols used for various components can be seen in the following table:
Component Symbol Example
Entity
Entity Student
Weak Entity
Weak Entity Assignments

Attribute

Attribute

Relationship

Relationship

Key Attribute

Attribute
14 Types of Attributes

• Simple attribute/Single-valued
attribute:
• Key attribute
• Composite attribute:
• Derived attribute:
• Multi-valued attribute:

27-10-2022
• Key Attribute for any Entity

To represent a Key attribute, the attribute name inside the Ellipse is underlined.
Entity-Relationship Diagrams 2-7
UNIVERSITY

14 > Attributes in the E-R model can be further classified as:

> A multi-valued attribute is illustrated with a double-line ellipse, which has more than
one value for at least one instance of its entity.
> This attribute may have upper and lower bounds specified for any individual entity
value.
> The telephone attribute of an individual may have one or more values, that is, an
individual can have one or more telephone numbers.
> Hence, the telephone attribute is a multi-valued attribute.
> The symbol and example of a multi-valued attribute can be seen in the following
figure:
Entity-Relationship Diagrams 3-7
15

Composite

> A composite attribute may itself contain two or more attributes, which represent
basic attributes having independent meanings of their own.
> The address attribute is usually a composite attribute, composed of attributes such as
street, area, and so on.
> The symbol and example of a composite attribute can be seen in the following figure:

Attribute Attribute

Composite
Attribute Address
Entity-Relationship Diagrams 4-7
16

Derived

> Derived attributes are attributes whose value is entirely dependent on another
attribute and are indicated by dashed ellipses.
> The age attribute of a person is the best example for derived attributes.
> For a particular person entity, the age of a person can be determined from the
current date and the person's birth date.
> The symbol and example of a derived attribute can be seen in the following figure:
Entity-Relationship Diagrams 5-7
17
Steps to construct an E-R diagram are as follows:
Entity-Relationship Diagrams 6-7
18

> Consider the scenario of a bank, with customers and accounts. The E-R diagram for
the scenario can be constructed as follows:

Step 1: Gather data •The bank is a collection of accounts used by customers to save money.

Step 2: Identify • Customer


entities • Account

Step 3: Identify the • Customer: customer_name, customer_address, customer_contact


attributes • Account: account_number, account_owner, balance_amount

Step 4: Sort entity • Customer entity set: weak entity set


sets • Account entity set: strong entity set

Step 5: Sort • Customer entity set: customer_address - composite, customer_contact - multi-valued


attributes • Account entity set: account_number primary key, account_owner - multi-valued

Step 6: Identify __ • A customer 'saves in' an account. The relation is 'saves in'. .
relations
Entity-Relationship Diagrams 7-7
19
JI
Step 7: Draw
diagram using • The E-R diagram is shown in the following figure:
symbols

customer_address account owner

customer name customer_contact account number balance

Customer Account
Relationship

□ Relationship represents an association between two or more entities.

□ One-to-One
□ One-to-Many
□ Many-to-One
□ Many-to-Many
.•A*.
>5-
Information Engineering
Style
> e --71V ,
ER Model: Keys

□A Key can be a single attribute or a group of attributes,


where the combination may act as a key.
□ Primary Key
□ Composite key
□ Candidate Key
□ Alternate Key
□ Super Key
□ Foreign Key
Examples — Primary Key

Primary Key for this table

student_id name age phone


Composite Key

□ Key that consists of two or more


attributes that uniquely identify any
record in a table is called Composite
Composite Key
key X
student_id subjected marks exam_name

Score Table - To save scores of the student for


various subjects.
Examples — Primary Key
UNIVERSITY
28 IIMX4

OrderLine
1 Ord«rNum 1 i PartNum ! NumOrdared I 1 Quo'tedl Pries 1

21608 AT94 11 •21.95

21610 DR93 1 3495.00

21610 T7W11 1 3399.99


21613 KL62 4 3329.95

21614 KT03 2 $595.00


21617 BV06 2 $794.95
21617 CD52 4 3150.00

21613 TYR93 1 $495.00


21623 KV29 2 $1,290 00

A A

Ordernum and Partnum makes up the primary key


Of the OrderLine table. This is what is known as a Composite
Primary key, that is, primary key that is made up of more
than one field.
Alternate key

□ Alternate key is a column or group of columns in a table


that uniquely identify every row in that table.
A table can have multiple choices for a primary key but
only one can be set as the primary key.
□ All the keys which are not primary key are called an
Alternate Key.
Candidate Key

□ Candidate keys are defined as the minimal set of fields which can uniquely identify
each record in a table. It is an attribute or a set of attributes that can act as a
Primary Key for a table to uniquely identify each record in that table. There can
be more than one candidate key.

□ In our example, student_id and phone both are candidate keys for table Student.

□ CANDIDATE KEY is a set of attributes that uniquely identify tuples in a table.


Candidate Key is a super key with no repeated attributes.

□ A candidate key can never be NULL or empty. And its value should be unique.
Super Key

□ Super Key is defined as a set of attributes within a table that can


A candidate key is a super key but vice versa is not true.

uniquely identify each record within a table. Super Key is


a superset of Candidate key.

□ student_id, (student_id, name), phoneetc.

student_id name phone age

1 Akon 9876723452 17

2 Akon 9991165674 19

3 Bkon 7898756543 18

4 Ckon 8987867898 19

5 Dkon 9990080080 17

Q
)
(
B
Foreign Key

□ Foreign Keys help us in establishing relationships with other tables. It is


also called Referential Integrity.
□ A Foreign Key column can be added to a table to establish this
relationship.
□ They help us in maintaining data integrity and allow easy navigation
between any instances of two entities.
Department Dept Id
IT □ 101
Accountinq □ 102
HR D103

Emp Id First Name Mobile No. □ept Id

E101 Ally 9848785252 D102

E102 Ben 9695943654 D102

E103 Cathy 8170502364 D103

You might also like