Sunteți pe pagina 1din 26

ER diagrams

What are Entity Relationship Diagrams?


Entity Relationship Diagrams (ERDs) illustrate the
logical structure of databases.

Cardinality
Cardinality specifies how many instances of an
entity relate to one instance of another entity.

Recursive relationship
In some cases, entities can be self-linked.
For example, employees can supervise
other employees.

Entity Classes and Attributes


Entity Class are represented by rectangles
Attributes are represented by ovals
Key attribute is represented by an underline
Multivalued attributes is represented with an
oval with a double border
Derived attribute is represented with an oval
dashed border -- Example the AGE from current birth
Composite attribute is represented with an oval
that connects to additional ovals

E-R Diagram for Entity ClassCustomer

E-R diagram for the entity class Video.

Relationship Types and Constraints

a store owns a video

A relationship type is represented by a diamond


and two connecting lines.
The name of the relationship is shown inside the
diamond.
Reading the diagram from left to right to yields "a
store owns a video"..
The name of the relationship type is a verb or verb
phrase that describes the relationship.
The alternate relationship name IsOwnedBy is the
name of the relationship type when reading the
other direction.

E-R Diagram for the Owns Relationship Type Showing


Cardinality and Participation Constraints

A relationship between the customer and the video


is created when the customer rents the video. The
relationship is removed when the customer returns
the video.

E-R Diagram of Relationship Type PreviouslyRented

capture the history with using previous


information.
The relationship type PreviouslyRented is manyto-many because each customer may have
previously rented many videos and each video
may have been rented many times.

The participations are optional for both customers


and videos.

E-R Diagram of a Combined Current


and Previous Rental Relationship Type

Modeling Rentals as an Entity Class


look at this is rental as an entity and not simply a
relationship.

referring to a "rental" as an object


Each rental entity has three attributes: date
Due, dateRented, and cost
The relationship types are called Has.
These are the relationship sentences for the
diagram.
A customer may have many rentals.
A rental must have one customer.
A rental must have one video.
A video may have no more than one rental

An E-R Diagram Showing Weak Entity Class Rental

-have an entity with no distinguishing attributes that is


partly identified by its relationship to other entities.

-call this a weak entity and class Rental a weak entity


class.

Roles in Relationship Types

Relationship TypesIsMarriedToandIsChildOf,with Role Names

A person may be the child of one or two


parents
A person may be the parent of zero or more
children
A person may be the wife of a husband
A person may be the husband of a wife

S-ar putea să vă placă și