Entity –Relationship-Diagram

  • View
    318

  • Download
    0

Embed Size (px)

Text of Entity –Relationship-Diagram

Entity Relationship Diagram

Entity Relationship DiagramEntities 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-DiagramThe concepts of the Entity-Relationship-Diagram Entity Attribute Record Table File Cardinality key

Cont sTypes of Relationship One-to-relationship One-to-many-relationship Many-to-many relationship Recursive Relationship

Entity-Relationship diagramTerminology 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 diagramA sample relation- FILMattributes

Degree=6

FilmNo 005 006 008 009 107

Title Reservoir dogs Pulp fiction Trainspotting Titanic Dirty pretty things

Director Tarantino Tarantino Boyle Cameron Frears

Country US US UK US UK

Year 1992 1994 1996 1997 2002

Genre Crime Crime Disaster crime

Cardinality=5

relation

tuple

Entity-Relationship diagramThe 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 diagramKey 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 diagramPrimary 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 diagramExample An 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 stockProductProduct no (PK) Description price

Entity-Relationship diagramE-R diagram for product and depotsdepotDepot no.(PK) Location

stock Holds 1..1 1..*representsDepot no.(PK,FK)Product no.(PK,FK)

product 0..* 1..1Product no.(PK) Description Price

quantity

Types of Relationship

Staff entity type (Staff No)

ManagesRelationship type

Branch entity type(branch No)

SG6

R1

B001

SG35 SL20 Figure 1 R2 B002

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 RelationshipEach branch is managed by one member of staff A member of staff can manage zero or one branch

Staff Staff No 1..1 0..1

Branch Branch No

Multiplicity

Entity-Diagram RelationshipOne to many relationshipcustomer customer no 1..1

places0..*

order order no

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 RelationshipMany to many relationshipdepot Depot no 1..*

HeldAt0..*

product Product no

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 DiagramDecomposition 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 diagramDecomposition exampledepotDepot no. etc

stock Holds 1..1 1..*representsStock no.

productProduct no

0..*

1..1

Entity-Diagram RelationshipRecursive relationshipEmployee Employee no. etc1..20

Manages1..1

Employee(manager) Employee no. etc

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