0% found this document useful (0 votes)
6 views55 pages

Week 3_Reduction of ER Model to Tables

The document discusses database design using the Entity-Relationship (E-R) model, detailing how entity sets and relationship sets can be represented as relation schemas. It covers various aspects of schema representation, including strong and weak entities, composite and multivalued attributes, and the implications of redundancy in schemas. Additionally, it addresses design issues, common mistakes, and the transition from E-R diagrams to UML class diagrams.

Uploaded by

mickeyushie
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)
6 views55 pages

Week 3_Reduction of ER Model to Tables

The document discusses database design using the Entity-Relationship (E-R) model, detailing how entity sets and relationship sets can be represented as relation schemas. It covers various aspects of schema representation, including strong and weak entities, composite and multivalued attributes, and the implications of redundancy in schemas. Additionally, it addresses design issues, common mistakes, and the transition from E-R diagrams to UML class diagrams.

Uploaded by

mickeyushie
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/ 55

Database Design Using the E-R Model

Database System Concepts, 7th Ed.


©Silberschatz, Korth and Sudarshan
See www.db-book.com
www.db-book.com for conditions on re-use
Reduction to Relation Schemas

Database System Concepts - 7th Edition 6.2 ©Silberschatz, Korth and Sudarshan
Reduction to Relation Schemas

▪ Entity sets and relationship sets can be expressed uniformly as relation


schemas that represent the contents of the database.
▪ A database which conforms to an E-R diagram can be represented by a
collection of schemas.
▪ For each entity set and relationship set there is a unique schema that is
assigned the name of the corresponding entity set or relationship set.
▪ Each schema has a number of columns (generally corresponding to
attributes), which have unique names.

Database System Concepts - 7th Edition 6.3 ©Silberschatz, Korth and Sudarshan
Representing Entity Sets

▪ A strong entity set reduces to a schema with the same attributes

student(ID, name, tot_cred)

▪ A weak entity set becomes a table that includes a column for the primary
key of the identifying strong entity set
section ( course_id, sec_id, sem, year )
▪ Example

Database System Concepts - 7th Edition 6.4 ©Silberschatz, Korth and Sudarshan
Representation of Entity Sets with Composite Attributes

▪ Composite attributes are flattened out by creating a


separate attribute for each component attribute
• Example: given entity set instructor with composite
attribute name with component attributes first_name
and last_name the schema corresponding to the
entity set has two attributes name_first_name and
name_last_name
▪ Prefix omitted if there is no ambiguity
(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.5 ©Silberschatz, Korth and Sudarshan
Representation of Entity Sets with Multivalued Attributes

▪ A multivalued attribute M of an entity E is represented by a separate


schema EM
▪ Schema EM has attributes corresponding to the primary key of E and
an attribute corresponding to multivalued attribute M
▪ Example: Multivalued attribute phone_number of instructor is
represented by a schema:
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.6 ©Silberschatz, Korth and Sudarshan
Representing Relationship Sets

▪ A many-to-many relationship set is represented as a schema with


attributes for the primary keys of the two participating entity sets, and
any descriptive attributes of the relationship set.
▪ Example: schema for relationship set advisor

advisor = (s_id, i_id)

Database System Concepts - 7th Edition 6.7 ©Silberschatz, Korth and Sudarshan
Redundancy of Schemas

▪ Many-to-one and one-to-many relationship sets that are total on the


many-side can be represented by adding an extra attribute to the “many”
side, containing the primary key of the “one” side
▪ Example: Instead of creating a schema for relationship set inst_dept, add
an attribute dept_name to the schema arising from entity set instructor
▪ Example

Database System Concepts - 7th Edition 6.8 ©Silberschatz, Korth and Sudarshan
Redundancy of Schemas (Cont.)

▪ For one-to-one relationship sets, either side can be chosen to act as the
“many” side
• That is, an extra attribute can be added to either of the tables
corresponding to the two entity sets

▪ Note: If participation is partial on the “many” side, replacing a schema by


an extra attribute in the schema corresponding to the “many” side could
result in null values

Database System Concepts - 7th Edition 6.9 ©Silberschatz, Korth and Sudarshan
Redundancy of Schemas (Cont.)

▪ The schema corresponding to a relationship set linking a weak entity set


to its identifying strong entity set is redundant.
▪ Example: The section schema already contains the attributes that would
appear in the sec_course schema

Database System Concepts - 7th Edition 6.10 ©Silberschatz, Korth and Sudarshan
Extended E-R Features

Database System Concepts - 7th Edition 6.11 ©Silberschatz, Korth and Sudarshan
Specialization

▪ Top-down design process; we designate sub-groupings within an entity set


that are distinctive from other entities in the set.
▪ These sub-groupings become lower-level entity sets that have attributes or
participate in relationships that do not apply to the higher-level entity
set.
▪ Depicted by a triangle component labeled ISA (e.g., instructor “is a”
person).
▪ Attribute inheritance – a lower-level entity set inherits all the attributes
and relationship participation of the higher-level entity set to which it is
linked.

Database System Concepts - 7th Edition 6.12 ©Silberschatz, Korth and Sudarshan
Specialization Example
▪ Overlapping – employee and student
▪ Disjoint – instructor and secretary
▪ Total and partial

Database System Concepts - 7th Edition 6.13 ©Silberschatz, Korth and Sudarshan
Representing Specialization via Schemas

▪ Method 1:
• Form a schema for the higher-level entity
• Form a schema for each lower-level entity set, include primary key
of higher-level entity set and local attributes

• Drawback: getting information about, an employee requires


accessing two relations, the one corresponding to the low-level
schema and the one corresponding to the high-level schema

Database System Concepts - 7th Edition 6.14 ©Silberschatz, Korth and Sudarshan
Representing Specialization as Schemas (Cont.)

▪ Method 2:
• Form a schema for each entity set with all local and inherited
attributes

• Drawback: name, street and city may be stored redundantly for


people who are both students and employees

Database System Concepts - 7th Edition 6.15 ©Silberschatz, Korth and Sudarshan
Completeness constraint

▪ Completeness constraint -- specifies whether or not an entity in the


higher-level entity set must belong to at least one of the lower-level
entity sets within a generalization.
• total: an entity must belong to one of the lower-level entity sets
• partial: an entity need not belong to one of the lower-level entity
sets

Database System Concepts - 7th Edition 6.17 ©Silberschatz, Korth and Sudarshan
Completeness constraint (Cont.)

▪ Partial generalization is the default.


▪ We can specify total generalization in an ER diagram by adding the
keyword total in the diagram and drawing a dashed line from the keyword
to the corresponding hollow arrow-head to which it applies (for a total
generalization), or to the set of hollow arrow-heads to which it applies (for
an overlapping generalization).
▪ Example: The student generalization is total:
• All student entities must be either graduate or undergraduate.
• Because the higher-level entity set arrived at through generalization is
generally composed of only those entities in the lower-level entity
sets, the completeness constraint for a generalized higher-level
entity set is usually total

Database System Concepts - 7th Edition 6.18 ©Silberschatz, Korth and Sudarshan
Aggregation

▪ Consider the ternary relationship proj_guide, which we saw earlier


▪ Suppose we want to record evaluations of a student by a guide on a
project

Database System Concepts - 7th Edition 6.19 ©Silberschatz, Korth and Sudarshan
Aggregation (Cont.)

▪ Relationship sets eval_for and proj_guide represent overlapping


information
• Every eval_for relationship corresponds to a proj_guide relationship
• However, some proj_guide relationships may not correspond to any
eval_for relationships
▪ So we can’t discard the proj_guide relationship
▪ Eliminate this redundancy via aggregation
• Treat relationship as an abstract entity
• Allows relationships between relationships
• Abstraction of relationship into new entity

Database System Concepts - 7th Edition 6.20 ©Silberschatz, Korth and Sudarshan
Aggregation (Cont.)

▪ Eliminate this redundancy via aggregation without introducing


redundancy, the following diagram represents:
• A student is guided by a particular instructor on a particular project
• A student, instructor, project combination may have an associated
evaluation

Database System Concepts - 7th Edition 6.21 ©Silberschatz, Korth and Sudarshan
Reduction to Relational Schemas

▪ To represent aggregation, create a schema containing


• Primary key of the aggregated relationship,
• The primary key of the associated entity set
• Any descriptive attributes
▪ In our example:
• The schema eval_for is:
eval_for (s_ID, project_id, i_ID, evaluation_id)
• The schema proj_guide is redundant.

Database System Concepts - 7th Edition 6.22 ©Silberschatz, Korth and Sudarshan
Design Issues

Database System Concepts - 7th Edition 6.23 ©Silberschatz, Korth and Sudarshan
Design of an E-R Database Schema

▪ The E-R data model gives us much flexibility in designing a database schema to
model a given enterprise
▪ Among the designer’s decisions are:
• Whether to use an attribute or an entity set to represent an object.
• Whether a real-world concept is expressed more accurately by an entity set
or by a relationship set.
• Whether to use a ternary relationship or a pair of binary relationships.
• Whether to use a strong or a weak entity set ; a strong entity set and its
dependent weak entity sets may be regarded as a single “object” in the
database, since weak entities are existence dependent on a strong entity.
• Whether using generalization is appropriate; generalization, or a hierarchy of
ISA relationships, contributes to modularity by allowing common attributes of
similar entity sets to be represented in one place in an E-R diagram.
• Whether using aggregation is appropriate; aggregation groups a part of an E-
R diagram into a single entity set, allowing us to treat the aggregate entity
set as a single unit without concern for the details of its internal structure.

Database System Concepts - 7th Edition 6.24 ©Silberschatz, Korth and Sudarshan
Common Mistakes in E-R Diagrams

▪ Example of erroneous E-R diagrams

Database System Concepts - 7th Edition 6.25 ©Silberschatz, Korth and Sudarshan
Common Mistakes in E-R Diagrams (Cont.)

Database System Concepts - 7th Edition 6.26 ©Silberschatz, Korth and Sudarshan
Entities vs. Attributes

▪ Use of entity sets vs. attributes

▪ Use of phone as an entity allows extra information about phone numbers


(plus multiple phone numbers)

Database System Concepts - 7th Edition 6.27 ©Silberschatz, Korth and Sudarshan
Entities vs. Relationship sets

▪ Use of entity sets vs. relationship sets


Possible guideline is to designate a relationship set to describe
an action that occurs between entities

▪ Placement of relationship attributes


For example, attribute date as attribute of advisor or as attribute
of student

Database System Concepts - 7th Edition 6.28 ©Silberschatz, Korth and Sudarshan
Summary of Symbols Used in E-R Notation

Database System Concepts - 7th Edition 6.29 ©Silberschatz, Korth and Sudarshan
Symbols Used in E-R Notation (Cont.)

Database System Concepts - 7th Edition 6.30 ©Silberschatz, Korth and Sudarshan
Alternative ER Notations

▪ Chen, IDE1FX, …

Database System Concepts - 7th Edition 6.31 ©Silberschatz, Korth and Sudarshan
Alternative ER Notations

Chen IDE1FX (Crows feet notation)

Database System Concepts - 7th Edition 6.32 ©Silberschatz, Korth and Sudarshan
UML

▪ UML: Unified Modeling Language


▪ A standard developed under the auspices of the Object Management
Group (OMG) for creating specifications of various components of a
software system.
▪ UML has many components to graphically model different aspects of an
entire software system
▪ UML Class Diagrams correspond to E-R Diagram, but several
differences.

Database System Concepts - 7th Edition 6.33 ©Silberschatz, Korth and Sudarshan
ER vs. UML Class Diagrams

* Note reversal of position in cardinality constraint depiction

Database System Concepts - 7th Edition 6.34 ©Silberschatz, Korth and Sudarshan
ER vs. UML Class Diagrams

ER Diagram Notation Equivalent in UML

* Generalization can use merged or separate arrows independent


of disjoint/overlapping

Database System Concepts - 7th Edition 6.35 ©Silberschatz, Korth and Sudarshan
UML Class Diagrams (Cont.)

▪ Binary relationship sets are represented in UML by just drawing a line


connecting the entity sets. The relationship set name is written adjacent
to the line.
▪ The role played by an entity set in a relationship set may also be
specified by writing the role name on the line, adjacent to the entity set.
▪ The relationship set name may alternatively be written in a box, along
with attributes of the relationship set, and the box is connected, using a
dotted line, to the line depicting the relationship set.

Database System Concepts - 7th Edition 6.36 ©Silberschatz, Korth and Sudarshan
ER vs. UML Class Diagrams

Database System Concepts - 7th Edition 6.37 ©Silberschatz, Korth and Sudarshan
Design Phases – Step-by-step

Database System Concepts - 7th Edition 6.38 ©Silberschatz, Korth and Sudarshan
Design Phases

▪ The initial phase of database design, is to characterize fully the data needs
of the prospective database users.
▪ The database designer needs to interact extensively with domain experts
and users to carry out this task.
▪ The outcome of this phase is a specification of user requirements.
▪ Next, the designer chooses a data model, and by applying the concepts of
the chosen data model, translates these requirements into a conceptual
schema of the database.

Database System Concepts - 7th Edition 6.39 ©Silberschatz, Korth and Sudarshan
Design Phases cont

▪ The schema developed at this conceptual-design phase provides a


detailed overview of the enterprise.
▪ Stated in terms of the E-R model, the schema specifies all entity sets,
relationship sets, attributes, and mapping constraints.
▪ The designer reviews the schema to confirm that all data requirements are
indeed satisfied and are not in conflict with one another. The design is
further examined and any/all redundant features removed
▪ The focus at this point is describing the data and their relationships, rather
than on specifying physical storage details.

Database System Concepts - 7th Edition 6.40 ©Silberschatz, Korth and Sudarshan
Design Phases cont

▪ A fully developed conceptual schema will also indicate the functional


requirements of the enterprise.
▪ In a specification of functional requirements, users describe the kinds
of operations (or transactions) that will be performed on the data. Example
operations include modifying or updating data, searching for and retrieving
specific data, and deleting data.
▪ At this stage of conceptual design, the designer can review the schema to
ensure it meets functional requirements.

Database System Concepts - 7th Edition 6.41 ©Silberschatz, Korth and Sudarshan
Design Phases cont

▪ The process of moving from an abstract data model to the implementation


of the database proceeds in two final design phases.
• Logical-design phase, The designer maps the high-level conceptual
schema onto the implementation data model of the database system
that will be used.
• Physical-design phase: The resulting system-specific database
schema is used to specify physical features of the database such as
the form of file organization and the internal storage structures.

Database System Concepts - 7th Edition 6.42 ©Silberschatz, Korth and Sudarshan
APPLY THE CONCEPTS
LEARNED

Database System Concepts - 7th Edition 6.43 ©Silberschatz, Korth and Sudarshan
Database Design for a University Organization

▪ To illustrate the design process, let us examine how a database for a


university could be designed.
▪ The initial specification of user requirements may be based on
interviews with the database users, and on the designer’s own analysis
of the organization.
▪ The description that arises from this design phase serves as the basis
for specifying the conceptual structure of the database.
▪ Here are the major characteristics of the university.

Database System Concepts - 7th Edition 6.44 ©Silberschatz, Korth and Sudarshan
Database Design for a University Organization cont

▪ The university is organized into departments.


▪ Each department is identified by a unique name (dept name), is located in a
particular building, and has a budget.
▪ Each department has a list of courses it offers.
▪ Each course has associated with it a course id, title, dept name, and credits, and
may also have associated prerequisites.
▪ Instructors are identified by their unique ID. Each instructor has name,
associated department (dept name), and salary.
▪ Students are identified by their unique ID. Each student has a name, an
associated major department (dept name), and tot cred (total credit hours the
student earned thus far).

Database System Concepts - 7th Edition 6.45 ©Silberschatz, Korth and Sudarshan
Entity Sets Designation

▪ classroom: with attributes (building, room number, capacity).


▪ department: with attributes (dept name, building, budget).
▪ course: with attributes (course id, title, credits).
▪ instructor: with attributes (ID, name, salary).
▪ section: with attributes (course id, sec id, semester, year).
▪ student: with attributes (ID, name, tot cred).
▪ time slot: with attributes (time slot id, {(day, start time, end time) }).

Database System Concepts - 7th Edition 6.46 ©Silberschatz, Korth and Sudarshan
Relationship Sets

▪ The relationship sets in our design are listed below:


▪ inst dept: relating instructors with departments.
▪ stud dept: relating students with departments.
▪ teaches: relating instructors with sections.
▪ takes: relating students with sections, with a descriptive attribute grade.
▪ course dept: relating courses with departments.
▪ sec course: relating sections with courses.
▪ sec class: relating sections with classrooms.
▪ sec time slot: relating sections with time slots.
▪ advisor: relating students with instructors.
▪ prereq: relating courses with prerequisite courses.

Database System Concepts - 7th Edition 6.47 ©Silberschatz, Korth and Sudarshan
Exercise

▪ Verify that none of the entity sets has any attribute that is made
redundant by one of the relationship sets.
▪ Verify that all the information (other than constraints) in the relational
schema for the university database has been captured by the above
design, but with several attributes in the relational design replaced by
relationships in the E-R design.
▪ Reduce the E-R model into a relational model

Database System Concepts - 7th Edition 6.48 ©Silberschatz, Korth and Sudarshan
E – R Diagram

Database System Concepts - 7th Edition 6.49 ©Silberschatz, Korth and Sudarshan
EXAMPLE 2

DATABASE DESIGN FOR A


BANKING ENTERPRISE

Database System Concepts - 7th Edition 6.50 ©Silberschatz, Korth and Sudarshan
Database Design for a Banking Enterprise

▪ Bank Branches: City, Unique name, Assets


▪ Bank Customers: Customer-id, Name, Street, City, account (loan),
account officer/personal banker.
▪ Bank Employees: Employee-id, Name,
Phone No, Dependants, Manager, Start date (length of employment)
▪ Accounts: {Savings and Current, Joint account, Multiple accounts},
Unique account no, balance
▪ Loans: Originating branch, Loan number, Amount, Loan Payments, Date
and amount for payments

Database System Concepts - 7th Edition 6.51 ©Silberschatz, Korth and Sudarshan
Entity Sets Designation

▪ Branch entity set, with attributes branch-name, branch-city, and assets.


▪ Customer entity set, with attributes customer-id, customer-name,
customer-street; and customer-city. A possible additional attribute is
banker-name.
▪ Employee entity set, with attributes employee-id, employee-name,
telephoneNumber, salary, and manager. Additional descriptive features
are the multi-valued attribute dependent-name, the base attribute start-
date, and the derived attribute employment-length.

Database System Concepts - 7th Edition 6.52 ©Silberschatz, Korth and Sudarshan
Entity Sets Designation cont

▪ Two account entity sets—Savings-account and Checking-account—with


the common attributes of account-number and balance; in addition,
savings-account has the attribute interest-rate and checking-account has
the attribute overdraft-amount.
▪ Loan entity set, with the attributes loan-number, amount, and originating-
branch.
▪ The weak entity set Loan-payment, with attributes payment-number,
payment-date, and payment-amount.

Database System Concepts - 7th Edition 6.53 ©Silberschatz, Korth and Sudarshan
Relationship Sets Designation

▪ borrower, a many-to-many relationship set between customer and loan.


▪ loan-branch, a many-to-one relationship set that indicates in which branch a
▪ loan originated. Note that this relationship set replaces the attribute originating-
branch of the entity set loan.
▪ loan-payment, a one-to-many relationship from loan to payment, which
documents that a payment is made on a loan.
▪ depositor, with relationship attribute access-date, a many-to-many relationship
set between customer and account, indicating that a customer owns an
account.
▪ cust-banker,, a many-to-one relationship set expressing that a customer can
be advised by a bank employee, and that a bank employee can advise one or
more customers. Note that this relationship set has replaced the attribute
banker-name of the entity set customer.
▪ works-for, a relationship set between employee entities with role indicators
manager and worker; the mapping cardinalities express that an employee
works for only one manager and that a manager supervises one or more
employees. Note that this relationship set has replaced the manager attribute of
employee.

Database System Concepts - 7th Edition 6.54 ©Silberschatz, Korth and Sudarshan
Database System Concepts - 7th Edition 6.55 ©Silberschatz, Korth and Sudarshan
Goals of ER Modeling

▪ There are four goals of ER modeling:


• Capture all required data
• Ensure that data appears only once
• Model no data that is derivable from other data already modeled
• Locate data in a predictable, logical place

Database System Concepts - 7th Edition 6.56 ©Silberschatz, Korth and Sudarshan

You might also like