DB Lecture 4

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

Lecture 4

Dr. Nabil M. Eldakhly


Faculty of Computers and Information –
Department of AI-
AI-SAMS
&
The French University in Egypt (UFE)
Modeling Data in The Organization -
E-R Model
Entity-Relationship Diagram
(ERD)

Entity-relationship diagrams (ERD) are essential to modeling


anything from simple to complex databases, but the shapes
and notations used can be very confusing.
Conceptual Data Models establish a broad view of what should
be included in the model set. Conceptual ERDs can be used as
the foundation for logical data models.
─ They may also be used to form common relationships between
ER models as a basis for data model integration.
Entity-Relationship Diagram (ERD)-
ERD Entity Symbols

Entity Symbol Name Description

These shapes are independent from other


entities, and are often called parent
entities, since they will often have weak
Strong Entity
entities that depend on them. They will
also have a primary key, distinguishing
each occurrence of the entity.
Weak entities depend on some other
entity type. They don't have primary keys,
Weak Entity
and have no meaning in the diagram
without their parent entity.
Associative entities relate the instances of
several entity types. They also contain
Associative Entity
attributes specific to the relationship
between those entity instances.
Entity-Relationship Diagram (ERD)-
ERD Entity Symbols (Cont.)- Examples
Entity-Relationship Diagram (ERD)-
ERD Relationship Symbols

Relationship
Name Description
Symbol
Relationships are associations between or
among entities.
Relationship

Weak Relationships are connections


between a weak entity and its owner.
Weak Relationship
Entity-Relationship Diagram (ERD)-
ERD Relationship Symbols- Ex.
Entity-Relationship Diagram (ERD)-
ERD Attribute Symbols

Entity Symbol Name Description

Attributes are characteristics of an


Attribute entity, a many-to-many relationship, or a
one-to-one relationship.

Multivalued Multivalued attributes are those that are


Attribute can take on more than one value.

Derived attributes are attributes whose


Derived Attribute value can be calculated from related
attribute values.

Relationships are associations between


Relationship or among entities.
Entity-Relationship Diagram (ERD)-
ERD Attribute Symbols- Ex.
Convert Multivalued Attribute to
Relationship

The potentially multiple Prerequisite attribute of a COURSE


(shown as a multivalued attribute
attribute)) are also courses (and a course
may be a prerequisite for many other courses)
courses)..
̶ Thus, prerequisite attribute could be viewed as a bill- bill-of
of--
materials (sub- components) structure between courses, not a
sub-components)
multivalued attribute of COURSE
COURSE..
Representing prerequisites via a bill of-materials structure also
bill--of-
means that finding the prerequisites of a course and finding the
courses for which a course is a prerequisite both deal with
relationships between Entity Types.
Types.
A bill of materials (BOM) is a
structured list identifying all
materials and components
required to construct a
product, as well as the
instructions for procuring
and using the materials
Convert Multivalued Attribute to
Relationship

The employees potentially have multiple SKILL (shown as a


multivalued attribute ), but also could be viewed instead as a
attribute),
composite attribute (contains attributes
attributes:: the Skill Code,
Code, a Skill Title,
Title,
and the Skill Type
Type)) that we can convert to Entity Type.
Type.
one
one--to-
to-many one
one--to
to--many

̶ The employee may have one or more skills,


skills, and one or more skills may
be of one employee.
employee. This is a many- to-many relationship and we can
many-to-
convert it to two one to-many relationships)
one--to-
Entity-Relationship Diagram (ERD)-
ERD Attribute Symbols-
Other Attributes- 5- Composite Attribute
A composite-attribute :
̶ Attributes that can be further divided and represented into simple
attributes are called composite attributes.
attributes.
̶ example,
For example,
• The Name attribute can be divided into First Name,
Name, Middle Name,
Name,
and Last Name.
Name.
• The Address attribute is usually divided into House Number
Number,,
Street, City
Street, City,, State,
State, and Zip Code
Code..
̶ Composite attributes are represented by an oval connected with other
attribute ovals in an ER diagram
diagram..
Entity-Relationship Diagram (ERD)-
ERD Attribute Symbols-
Other Attributes- 5- Composite Attribute
Entity-Relationship Diagram (ERD)-
ERD Attribute Symbols-
Other Attributes- 6- Stored Attribute
A stored-attribute :
̶ The attributes whose values are stored in the database and which do
not change over a period of time are called Stored Attributes
Attributes..
̶ The values in Stored Attributes can be used to derive values for other
attributes
attributes..
̶ example, Date of Birth (DOB
For example, DOB)) and Basic Pay are examples of Stored
Attributes..
Attributes
̶ These are represented as ovals with a single outline in the ER diagram
diagram..
Cardinality Constraints

Cardinality Constraint-
Constraint- A rule that specifies the number of instances of one
entity that can (or must) be associated with each instance of another entity.
entity.
Minimum Cardinality
Cardinality-- The minimum number of instances of one entity that
may be associated with each instance of another entity
Maximum Cardinality-
Cardinality- The maximum number of instances of one entity that
may be associated with each instance of another entity
Cardinality Constraints (Cont.)

Basic Relationship

Relationship With Cardinality Constraints


Cardinality Constraints (Cont.)-
Example of relationships & their cardinalities

Mandatory cardinalities

One optional, one


mandatory
cardinality

Optional cardinalities
Cardinality Constraints (Cont.)-
Example of Relationships & their cardinalities (Cont.)

Cardinality constraints in a ternary relationship


Modeling Time-Dependent Data (Time Stamp)

Consider the following example


example-- in a database that contains product
information, the unit price for each product may be changed as
change.
material and labor costs and market conditions change.
̶ If only the current price is required
required,, Price can be modeled as a
single- attribute.
single-valued attribute.
̶ However, for accounting, billing, financial reporting, and other
purposes, we are likely to need to maintain a history of the prices
and the time period during which each was in effect
• We can conceptualize this requirement as a series of prices and the
effective date for each price.
o This results is the (composite) multivalued attribute named Price
History, with components Price and Effective Date.
o An important characteristic of such a
composite, multivalued attribute is that
the component attributes go together.
Modeling Time-Dependent Data (Time Stamp) (Cont.)

Each value of the attribute Price is time stamped with its effective
date.
date.
A time stamp is simply a time value,
value, such as date and time
time,, that is
value.
associated with a data value.
A time stamp may be associated with any data value that changes over
time when we need to maintain a history of those data values
values..
Time stamps may be recorded to indicate the time the value was
entered (transaction time)
time);; the time the value becomes valid or stops
being valid;
valid; or the time when critical actions were performed, such as
updates, corrections, or audits.
audits.
Modeling Multiple Relationships Between Entity Types
Naming & Defining Relationships

There are a few special guidelines for naming relationships, which


follow:
̶ A relationship name is a verb phrase (such as Assigned To, Supplies, or
Teaches) representing actions being taken, usually in the present tense.
• A relationship definition explains what action is being taken and possibly
why it is important.
̶ Should avoid vague names, such as Has or Is Related To.
̶ It may also be important to give examples to clarify the action.
• For example, for a relationship of Registered For between STUDENT and
COURSE.
̶ A relationship definition should also explain the reason for any explicit
maximum cardinality other than many.
̶ A relationship definition should explain any mutually exclusive
relationships.

You might also like