0% found this document useful (0 votes)
1K views21 pages

Entity - Relationship-Diagram

Uploaded by

Yaw Awuku Ankrah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views21 pages

Entity - Relationship-Diagram

Uploaded by

Yaw Awuku Ankrah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Entity –Relationship Diagram

Entity –Relationship Diagram


Entities and relationships can be used to
produce a pictorial representation of what an
organization is interested in. this picture is
called an entity-relationship diagram.
Entity –Relationship-Diagram

The concepts of the Entity-Relationship-Diagram


Entity
Attribute
Record
Table
File
Cardinality
key
Cont’s
Types of Relationship
 One-to-relationship
 One-to-many-relationship
 Many-to-many relationship
 Recursive –Relationship
Entity-Relationship diagram
Terminology
 Entity: an entity is a distinct object, like a person, place, thing
etc. In other words it is something which is described in the
database by storing its data.

 Attribute: a property that describes some aspect of the object


that wish to record.

 Domain: a set of permissible values for each attribute is called


domain.
(E.g. character, integer.)
Entity-Relationship diagram
 A Table: is a set of rows and columns

 A Tuple: is a row of a relation

 Degree of a relation: the number of attributes it


contains.

 Cardinality of relation: is the number of tuple it


contains.
Entity-Relationship diagram
A sample relation- FILM
attributes

Degree=6 FilmNo Title Director Country Year Genre


005 Reservoir dogs Tarantino US 1992 Crime
006 Pulp fiction Tarantino US 1994 Crime
008 Trainspotting Boyle UK 1996
Cardinality=5 009 Titanic Cameron US 1997 Disaster
107 Dirty pretty Frears UK 2002 crime
things

relation tuple
Entity-Relationship diagram
The domain for ‘year’ might be the range of
years when films have been made; the domain
for title ‘title’ might be ‘character’, size 30.
Entity-Relationship diagram
Key attributes
It may be necessary to specify one or more of the
attributes of an entity as a “key” of the entity;
this particularity true of the relational model.
Three 3 types of keys are defined here:

A candidate key is a unique identifier for the entity


–there may be more than one candidate key( for
example, customer-no, customer address)
Entity-Relationship diagram

 Primary key(PK)
Candidate key selected to identify tuples uniquely within
relation.

 Foreign key
is an attribute in a relation which is also the primary key in
another relation
 Secondary Key
it is a field or combination of fields that can be used to access
or retrieve records. It can also be used to sort or display records in
a certain order.
Entity-Relationship diagram
Example
An entity product may be describes by its name and its
associated attribute.

Product –no is the primary


Product key. We now introduce two
other entities, depot and stock
Product no (PK)
Description
price
Entity-Relationship diagram
E-R diagram for product and depots

depot stock product


Depot no.(PK) represents Product no.(PK)
Holds Depot no.(PK,FK) Description
Location
1..1 1..* Product no.(PK,FK) 0..* 1..1 Price
quantity
Types of Relationship
Staff entity type Manages Branch entity type
(Staff No) Relationship type (branch No)

SG6 R1 B001

SG35

SL20 R2 B002

Figure 1
One-to-One Relationship

• In figure 1 we see that staff No SG6 manage


branch B001 and staff No SL20 manages branch No
B002, but staffNo35 does not manage any branch.
As there are a maximum of one branch for each
member of staff involved in this relationship and
maximum of one member of staff for each branch,
we refer to this type of relationship as one-to-one
which we usually abbreviate as (1:1).
One-to-One Relationship
Each branch is managed A member of staff can
by one member of staff manage zero or one
branch

Staff Branch

Staff No 1..1 0..1 Branch No

Multiplicity
Entity-Diagram Relationship
One –to many relationship
customer order
places
customer no order no
1..1 0..*
Always start with the word “one”
Here an occurrence of the first entity type may be related to
several occurrences of the second, but each occurrence of the
second is related to a maximum of one occurrence of the first.
For the reading: One customer places zero or more orders; One
order is placed by one customer.
Entity-Diagram Relationship
Many –to many relationship
depot product
HeldAt
Depot no Product no
1..* 0..*
Always start with the word “one”
Here an occurrence of the first entity type may be related to
several occurrences of the second and vice versa.
For the reading: one depot holds zero or more products; one
product is held at 1 or more depots.
Entity –Relationship Diagram
Decomposition
All many -to -many relationship, can be
decomposed into two one-to-many
relationships.
One reason for doing this is that relational DBMSs
do not support many-to-many relationship
directly. Also, by eliminating many-to-many
relationships, problems in the model become
easier to spot.
Entity-Relationship diagram
Decomposition example

depot stock product


Depot no. represents Product no
Holds Stock no.
etc
1..1 1..* 0..* 1..1
Entity-Diagram Relationship
Recursive relationship
Employee Employee(manager)
Manages
Employee no. 1..20
Employee no.
1..1
Always
etc start with the word “one” etc
For the reading: one employee (a manger) manage one to
twenty employees; one employee is managed by one
employee(manager).

You might also like