Top Banner
Entity –Relationship Diagram
21
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Entity –Relationship-Diagram

Entity –Relationship Diagram

Page 2: 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.

Page 3: Entity –Relationship-Diagram

Entity –Relationship-Diagram

The concepts of the Entity-Relationship-DiagramEntityAttributeRecordTableFileCardinalitykey

Page 4: Entity –Relationship-Diagram

Cont’s

Types of RelationshipOne-to-relationshipOne-to-many-relationshipMany-to-many relationshipRecursive –Relationship

Page 5: Entity –Relationship-Diagram

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.)

Page 6: Entity –Relationship-Diagram

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.

Page 7: Entity –Relationship-Diagram

Entity-Relationship diagram

A sample relation- FILM

FilmNo Title Director Country Year Genre005 Reservoir dogs Tarantino US 1992 Crime006 Pulp fiction Tarantino US 1994 Crime008 Trainspotting Boyle UK 1996009 Titanic Cameron US 1997 Disaster107 Dirty pretty

thingsFrears UK 2002 crime

relation tuple

attributes

Degree=6

Cardinality=5

Page 8: Entity –Relationship-Diagram

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.

Page 9: Entity –Relationship-Diagram

Entity-Relationship diagram

Key attributesIt 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)

Page 10: Entity –Relationship-Diagram

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.

Page 11: Entity –Relationship-Diagram

Entity-Relationship diagram

ExampleAn entity product may be describes by its name and its

associated attribute.

Product –no is the primary key. We now introduce two other entities, depot and stockProduct

Product no (PK)Descriptionprice

Page 12: Entity –Relationship-Diagram

Entity-Relationship diagram

E-R diagram for product and depots

depot

Holds represents

stock product

1..*1..1 1..10..*Depot no.(PK)Location Depot no.(PK,FK)

Product no.(PK,FK)quantity

Product no.(PK)DescriptionPrice

Page 13: Entity –Relationship-Diagram

Types of Relationship

Page 14: Entity –Relationship-Diagram

Staff entity type Manages Branch entity type(Staff No) Relationship type (branch No)

SG35

SL20 R2 B002

Figure 1

SG6 R1 B001

Page 15: Entity –Relationship-Diagram

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).

Page 16: Entity –Relationship-Diagram

One-to-One Relationship

Each branch is managed by one member of staff

A member of staff can manage zero or one branch

Staff Branch

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

Multiplicity

Page 17: Entity –Relationship-Diagram

Entity-Diagram Relationship

One –to many relationship

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.

customer orderplaces

customer no order no0..*1..1

Page 18: Entity –Relationship-Diagram

Entity-Diagram Relationship

Many –to many relationship

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.

depot productHeldAt

Depot no Product no0..*1..*

Page 19: Entity –Relationship-Diagram

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.

Page 20: Entity –Relationship-Diagram

Entity-Relationship diagram

Decomposition example

depot

Holds represents

stock product

1..*1..1 1..10..*Depot no.etc Stock no.

Product no

Page 21: Entity –Relationship-Diagram

Entity-Diagram Relationship

Recursive relationship

Always start with the word “one”For the reading: one employee (a manger) manage one to

twenty employees; one employee is managed by one employee(manager).

Employee Employee(manager)Manages

Employee no.etc

Employee no.etc1..11..20