0% found this document useful (0 votes)
14 views40 pages

2 Er

Uploaded by

ahmedgamal7207
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views40 pages

2 Er

Uploaded by

ahmedgamal7207
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

The Entity-Relationship Model

The Importance of Data Models


• Data model
– Relatively simple representation, usually
graphical, of complex real-world data
structures
– Communications tool to facilitate interaction
among the designer, the applications
programmer, and the end user

• Good database design uses an appropriate


data model as its foundation
Importance of Data Modeling
• End-users have different views and needs for
data

• Data model organizes data for various users


Why Learn About Database Modeling?
• The way in which data is stored is very important for
subsequent access and manipulation by SQL.

• Properties of a good data model:


– It is easy to write correct and easy to understand queries.
– Minor changes in the problem domain do not change the
schema.
– Major changes in the problem domain can be handled without
too much difficulty.
– Can support efficient database access.
The Evolution of Data Models
• Hierarchical

• Network

• Relational

• Object oriented

• Object Relational
Business Rules (enforce
Constraints)
• Brief, precise, and unambiguous description
of a policy, procedure, or principle within a
specific organization’s environment

• Apply to any organization that stores and


uses data to generate information

• Description of operations that help to


create and enforce actions within that
organization’s environment
Business Rules
• Must be rendered in writing

• Must be kept up to date

• Sometimes are external to the organization

• Must be easy to understand and widely


disseminated

• Describe characteristics of the data as


viewed by the company
Sources of Business Rules
• Company managers
• Policy makers
• Department managers
• Written documentation
– Procedures
– Standards
– Operations manuals
• Direct interviews with end users
Importance of Business Rules
• Promote creation of an accurate data model
• Standardize company’s view of data
• Constitute a communications tool between users and
designers
• Allow designer to understand the nature, role, and
scope of data
• Allow designer to understand business processes
• Allow designer to develop appropriate relationship
participation rules and constraints
Purpose of E/R Model
• The E/R model allows us to sketch the design of a
database informally.
– Represent different types of data and how they relate to
each other
• Designs are pictures called entity-relationship diagrams.
• Fairly mechanical ways to convert E/R diagrams to real
implementations like relational databases exist.

10
Entity Sets

• Entity = “thing” or object.


• Entity set = collection of similar entities.
– Similar to a class in object-oriented languages.
• Attribute = property of an entity set.
– Generally, all entities in a set have the same
properties.
– Attributes are simple values, e.g. integers or
character strings.

11
Attributes

Database Systems, 8th Edition 12


Attributes (continued)
• Characteristics of entities
• Required attribute: must have a value
• Optional attribute: may be left empty
• Domain: set of possible values for an attribute
– Attributes may share a domain

Database Systems, 8th Edition 13


Attributes (continued)
• Composite attribute can be subdivided
• Simple attribute cannot be subdivided
• Single-value attribute can have only a single
value
• Multivalued attributes can have many values

Database Systems, 8th Edition 14


Attributes (continued)
• M:N relationships and multivalued attributes should not
be implemented
– Create several new attributes for each of the
original multivalued attributes components
– Create new entity composed of original
multivalued attributes components
• Derived attribute: value may be calculated
from other attributes
– Need not be physically stored within database

Database Systems, 8th Edition 15


E/R Diagrams
• In an entity-relationship diagram, each entity
set is represented by a rectangle.
• Each attribute of an entity set is represented
by an oval, with a line to the rectangle
representing its entity set.

16
Example
name manf

drinks

• Entity set drinks has two attributes, name and manf


(manufacturer).
• Each drink entity has values for these two attributes,
e.g. (coke, Anheuser-Busch)

17
Relationships
• A relationship connects two or more entity
sets.
• It is represented by a diamond, with lines to
each of the entity sets involved.

18
Example

name addr name manf


cafes sell some
drinks.

cafes Sells drinks

license

Note: Drinkers like


Frequents Likes
license = some drinks.
drink, full,
none

Drinkers
name addr

Drinkers frequent
some cafes. 19
Relationship Set
• The current “value” of an entity set is the set
of entities that belong to it.
– Example: the set of all cafes in our database.
• The “value” of a relationship is a set of lists of
currently related entities, one from each of
the related entity sets.

20
Example
• A relationship R between entity sets E and F relates some
entities in E to some entities in F.
• R is a set of pairs of tuples (e, f ) where e is in E and f is in F.

• For the relationship Sells, we might have a relationship set


like:
cafe drink
Joe’s cafe coke
Joe’s cafe pepsi
Sue’s cafe coke
Sue’s cafe apple juice
Sue’s cafe coke Lite

21
Multiway Relationships
• Sometimes, we need a relationship that
connects more than two entity sets.
• Suppose that drinkers will only drink certain
drinks at certain cafes.
– Our three binary relationships Likes, Sells, and
Frequents do not allow us to make this distinction.
– But a 3-way relationship would.

22
Example
name addr name manf

license cafes drinks

Preferences

Drinkers

name addr
23
A Typical Relationship Set

cafe Drinker drink


Joe’s cafe Ann pepsi
Sue’s cafe Ann coke
Sue’s cafe Ann apple juice
Joe’s cafe Bob coke
Joe’s cafe Bob pepsi
Joe’s cafe Cal pepsi
Sue’s cafe Cal coke Lite

24
Many-Many Relationships
• Think of a relationship between two entity
sets, such as Sells between cafes and drinks.
• In a many-many relationship, an entity of
either set can be connected to many entities
of the other set.
– E.g., a cafe sells many drinks; a drink is sold by
many cafes.

25
Many-One Relationships
• Some binary relationships are many -one from
one entity set to another.
• Each entity of the first set is connected to at
most one entity of the second set.
• But an entity of the second set can be
connected to zero, one, or many entities of
the first set.

26
Example
• Favorite, from Drinkers to drinks is many-one.
• A drinker has at most one favorite drink.
• But a drink can be the favorite of any number
of drinkers, including zero.

27
One-One Relationships

• In a one-one relationship, each entity of


either entity set is related to at most one
entity of the other set.
• Example: Relationship Best-seller between
entity sets Manfs (manufacturer) and drinks.
– A drink cannot be made by more than one
manufacturer, and no manufacturer can have
more than one best-seller (assume no ties).

28
Representing “Multiplicity”
• Show a many-one relationship by an arrow entering
the “one” side.
• Show a one-one relationship by arrows entering both
entity sets.
• In some situations, we can also assert “exactly one,”
i.e., each entity of one set must be related to exactly
one entity of the other set. To do so, we use a
rounded arrow.

29
Example

Drinkers Likes drinks

Favorite

30
Example
• Consider Best-seller between Manfs and
drinks.
• Some drinks are not the best-seller of any
manufacturer, so a rounded arrow to Manfs
would be inappropriate.
• But a manufacturer has to have a best-seller
(we assume they are drink manufacturers).

Manfs Best- drinks


seller

31
Attributes on Relationships
• Sometimes it is useful to attach an attribute to a
relationship.
• Think of this attribute as a property of tuples in the
relationship set.

cafes Sells drinks

price

Price is a function of both the cafe and the drink,


not of one alone. 32
Relationships
• Can the same entity set appear more than once in
the same relationship?
• Prerequisite relationship between two Courses

• Which course is the pre-requisite?


33
Roles
• Label the edges between the relationship and
the entity set with names called roles.

34
Example
Relationship Set

Husband Wife
Bob Ann
Joe Sue
… …
Married

husband wife

Drinkers

35
Example
Relationship Set

buddy1 buddy2
Bob Ann
Joe Sue
buddies Ann Bob
Joe Moe
… …
1 2

Drinkers

36
Parallel Relationships
• Can there be more than one relationship between
the same pair of entities?
• TA and Take relationship between Students and
Classes

37
Subclasses
• Subclass = special case = fewer entities = more
properties.
• Example: Juices are a kind of drink.
– Not every drink is a juice, but some are.
– Let us suppose that in addition to all the
properties (attributes and relationships) of drinks,
juices also have the attribute fruit.

38
Subclasses in E/R Diagrams
• Assume subclasses form a tree.
– i.e., no multiple inheritance.
• Isa triangles indicate the subclass relationship.
– Point to the superclass.

39
Example

name drinks manf

isa

fruit Juices

40

You might also like