E R Modeling
E R Modeling
Database System Concepts - 7th Edition 6.2 ©Silberschatz, Korth and Sudarshan
Initial phase -- characterize fully the data needs of the prospective Final Phase -- Moving from an abstract data model to the implementation
database users. of the database
Second phase -- choosing a data model • Logical Design – Deciding on the database schema.
• Applying the concepts of the chosen data model Database design requires that we find a “good” collection of
relation schemas.
• Translating these requirements into a conceptual schema of the
Business decision – What attributes should we record in the
database.
database?
• A fully developed conceptual schema indicates the functional Computer Science decision – What relation schemas should we
requirements of the enterprise. have and how should the attributes be distributed among the
Describe the kinds of operations (or transactions) that will be various relation schemas?
performed on the data. • Physical Design – Deciding on the physical layout of the database
Database System Concepts - 7th Edition 6.3 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.4 ©Silberschatz, Korth and Sudarshan
In designing a database schema, we must ensure that we avoid two Entity Relationship Model
major pitfalls: Models an enterprise as a collection of entities and relationships
• Redundancy: a bad design may result in repeat information. Entity: a “thing” or “object” in the enterprise that is distinguishable
Redundant representation of information may lead to data from other objects
inconsistency among the various copies of information • Described by a set of attributes
• Incompleteness: a bad design may make certain aspects of the Relationship: an association among several entities
enterprise difficult or impossible to model.
• Represented diagrammatically by an entity-relationship diagram:
Avoiding bad designs is not enough. There may be a large number of
good designs from which we must choose. Normalization Theory
Formalize what designs are bad, and test for them
Database System Concepts - 7th Edition 6.5 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.6 ©Silberschatz, Korth and Sudarshan
1
ER model -- Database Modeling
Database System Concepts - 7th Edition 6.7 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.8 ©Silberschatz, Korth and Sudarshan
Database System Concepts - 7th Edition 6.9 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.10 ©Silberschatz, Korth and Sudarshan
Entity sets can be represented graphically as follows: A relationship is an association among several entities
• Rectangles represent entity sets. Example:
• Attributes listed inside entity rectangle 44553 (Peltier) advisor 22222 (Einstein)
student entity relationship set instructor entity
• Underline indicates primary key attributes
A relationship set is a mathematical relation among n 2 entities, each
taken from entity sets
{(e1, e2, … en) | e1 E1, e2 E2, …, en En}
Database System Concepts - 7th Edition 6.11 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.12 ©Silberschatz, Korth and Sudarshan
2
Relationship Sets (Cont.) Representing Relationship Sets via ER Diagrams
Example: we define the relationship set advisor to denote the Diamonds represent relationship sets.
associations between students and the instructors who act as their
advisors.
Pictorially, we draw a line between related entities.
Database System Concepts - 7th Edition 6.13 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.14 ©Silberschatz, Korth and Sudarshan
student
Database System Concepts - 7th Edition 6.15 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.16 ©Silberschatz, Korth and Sudarshan
Database System Concepts - 7th Edition 6.17 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.18 ©Silberschatz, Korth and Sudarshan
3
Non-binary Relationship Sets Complex Attributes
Database System Concepts - 7th Edition 6.19 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.20 ©Silberschatz, Korth and Sudarshan
component
attributes
street_number street_name apartment_number
Database System Concepts - 7th Edition 6.21 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.22 ©Silberschatz, Korth and Sudarshan
Database System Concepts - 7th Edition 6.23 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.24 ©Silberschatz, Korth and Sudarshan
4
Mapping Cardinalities Representing Cardinality Constraints in ER Diagram
Database System Concepts - 7th Edition 6.25 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.26 ©Silberschatz, Korth and Sudarshan
one-to-many relationship between an instructor and a student In a many-to-one relationship between an instructor and a student,
• an instructor is associated with several (including 0) students via • an instructor is associated with at most one student via advisor,
advisor
• and a student is associated with several (including 0) instructors via
• a student is associated with at most one instructor via advisor, advisor
Database System Concepts - 7th Edition 6.27 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.28 ©Silberschatz, Korth and Sudarshan
Database System Concepts - 7th Edition 6.29 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.30 ©Silberschatz, Korth and Sudarshan
5
Reduction to Relation Schemas
Database System Concepts - 7th Edition 6.31 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.32 ©Silberschatz, Korth and Sudarshan
A strong entity set reduces to a schema with the same attributes Composite attributes are flattened out by creating a
separate attribute for each component attribute
student(ID, name, tot_cred) • Example: given entity set instructor with composite
attribute name with component attributes first_name
A weak entity set becomes a table that includes a column for the primary and last_name the schema corresponding to the
key of the identifying strong entity set entity set has two attributes name_first_name and
name_last_name
section ( course_id, sec_id, sem, year )
Prefix omitted if there is no ambiguity
Example (name_first_name could be first_name)
Ignoring multivalued attributes, extended instructor
schema is
• instructor(ID,
first_name, middle_initial, last_name,
street_number, street_name,
apt_number, city, state, zip_code,
date_of_birth)
Database System Concepts - 7th Edition 6.33 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.34 ©Silberschatz, Korth and Sudarshan
A multivalued attribute M of an entity E is represented by a separate A many-to-many relationship set is represented as a schema with
schema EM attributes for the primary keys of the two participating entity sets, and
any descriptive attributes of the relationship set.
Schema EM has attributes corresponding to the primary key of E and an
attribute corresponding to multivalued attribute M Example: schema for relationship set advisor
Example: Multivalued attribute phone_number of instructor is
represented by a schema: advisor = (s_id, i_id)
inst_phone= ( ID, phone_number)
Each value of the multivalued attribute maps to a separate tuple of the
relation on schema EM
• For example, an instructor entity with primary key 22222 and phone
numbers 456-7890 and 123-4567 maps to two tuples:
(22222, 456-7890) and (22222, 123-4567)
Database System Concepts - 7th Edition 6.35 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.36 ©Silberschatz, Korth and Sudarshan
6
Redundancy of Schemas Redundancy of Schemas (Cont.)
Many-to-one and one-to-many relationship sets that are total on the many- For one-to-one relationship sets, either side can be chosen to act as the
side can be represented by adding an extra attribute to the “many” side, “many” side
containing the primary key of the “one” side • That is, an extra attribute can be added to either of the tables
Example: Instead of creating a schema for relationship set inst_dept, add corresponding to the two entity sets
an attribute dept_name to the schema arising from entity set instructor If participation is partial on the “many” side, replacing a schema by an
Example extra attribute in the schema corresponding to the “many” side could
result in null values
Database System Concepts - 7th Edition 6.37 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.38 ©Silberschatz, Korth and Sudarshan
The schema corresponding to a relationship set linking a weak entity set UML: Unified Modeling Language
to its identifying strong entity set is redundant.
UML has many components to graphically model different aspects of an
Example: The section schema already contains the attributes that would entire software system
appear in the sec_course schema
UML Class Diagrams correspond to E-R Diagram, but several
differences.
Database System Concepts - 7th Edition 6.39 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.40 ©Silberschatz, Korth and Sudarshan
* Note reversal of position in cardinality constraint depiction * Generalization can use merged or separate arrows independent
of disjoint/overlapping
Database System Concepts - 7th Edition 6.41 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.42 ©Silberschatz, Korth and Sudarshan
7
UML Class Diagrams (Cont.) ER vs. UML Class Diagrams
Database System Concepts - 7th Edition 6.43 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.44 ©Silberschatz, Korth and Sudarshan