Date post: | 26-Nov-2014 |
Category: |
Documents |
Upload: | yaw-awuku-ankrah |
View: | 341 times |
Download: | 0 times |
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-DiagramEntityAttributeRecordTableFileCardinalitykey
Cont’s
Types of RelationshipOne-to-relationshipOne-to-many-relationshipMany-to-many relationshipRecursive –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
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
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 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)
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
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
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
Types of Relationship
Staff entity type Manages Branch entity type(Staff No) Relationship type (branch No)
SG35
SL20 R2 B002
Figure 1
SG6 R1 B001
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 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
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
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..*
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
Holds represents
stock product
1..*1..1 1..10..*Depot no.etc Stock no.
Product no
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