0% found this document useful (0 votes)
12 views8 pages

E R Modeling

Uploaded by

prince deno
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)
12 views8 pages

E R Modeling

Uploaded by

prince deno
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/ 8

Outline

 Extended E-R Features


 Entity-Relationship Design Issues
 Alternative Notations for Modeling Data
 Other Aspects of Database Design

Database Design Using the E-R Model

Database System Concepts, 7th Ed.


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

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

Design Phases Design Phases (Cont.)

 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

Design Alternatives Design Approaches

 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

 The ER data mode was developed to facilitate database design by


allowing specification of an enterprise schema that represents the
overall logical structure of a database.
 The ER data model employs three basic concepts:
• entity sets,
• relationship sets,
Outline of the ER Model • attributes.
 The ER model also has an associated diagrammatic representation, the
ER diagram, which can express the overall logical structure of a
database graphically.

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

Entity Sets Entity Sets -- instructor and student

 An entity is an object that exists and is distinguishable from other


objects.
• Example: specific person, company, event, plant
 An entity set is a set of entities of the same type that share the same
properties.
• Example: set of all persons, companies, trees, holidays
 An entity is represented by a set of attributes; i.e., descriptive properties
possessed by all members of an entity set.
• Example:
instructor = (ID, name, salary )
course= (course_id, title, credits)
 A subset of the attributes form a primary key of the entity set; i.e.,
uniquely identifying each member of the set.

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

Representing Entity sets in ER Diagram Relationship Sets

 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}

where (e1, e2, …, en) is a relationship


• Example:
(44553,22222)  advisor

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

Relationship Sets (Cont.) Relationship Sets with Attributes

 An attribute can also be associated with a relationship set.


 For instance, the advisor relationship set between entity sets instructor
and student may have the attribute date which tracks when the student
started being associated with the advisor

76766 Crick 98988 Tanaka


45565 Katz 3 May 2008 12345 Shankar
10 June 2007
10101 Srinivasan 12 June 2006
00128 Zhang
98345 Kim 6 June 2009 76543 Brown
76543 Singh 30 June 2007
76653 Aoi
31 May 2007
22222 Einstein 23121 Chavez
4 May 2006

instructor 44553 Peltier

student

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

Roles Degree of a Relationship Set

 Entity sets of a relationship need not be distinct  Binary relationship


• Each occurrence of an entity set plays a “role” in the relationship • involve two entity sets (or degree two).
 The labels “course_id” and “prereq_id” are called roles. • most relationship sets in a database system are binary.
 Relationships between more than two entity sets are rare. Most
relationships are binary. (More on this later.)
• Example: students work on research projects under the guidance of
an instructor.
• relationship proj_guide is a ternary relationship between instructor,
student, and project

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

 Most relationship sets are binary  Attribute types:


 There are occasions when it is more convenient to represent • Simple and composite attributes.
relationships as non-binary. • Single-valued and multivalued attributes
 E-R Diagram with a Ternary Relationship  Example: multivalued attribute: phone_numbers
• Derived attributes
 Can be computed from other attributes
 Example: age, given date_of_birth
 Domain – the set of permitted values for each attribute

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

Composite Attributes Representing Complex Attributes in ER Diagram

 Composite attributes allow us to divided attributes into subparts (other


attributes).

composite name address


attributes

first_name middle_initial last_name street city state postal_code

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

Mapping Cardinality Constraints Mapping Cardinalities

 Express the number of entities to which another entity can be associated


via a relationship set.
 Most useful in describing binary relationship sets.
 The cardinality of a relationship is the number of related rows for
each of the two objects in the relationship.
 For a binary relationship set the mapping cardinality must be one of the
following types:
• One to one
• One to many
• Many to one
• Many to many
One to one One to many

Note: Some elements in A and B may not be mapped to any


elements in the other set

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

 We express cardinality constraints by drawing either a directed line (),


signifying “one,” or an undirected line (—), signifying “many,” between the
relationship set and the entity set.

 One-to-one relationship between an instructor and a student :


• A student is associated with at most one instructor via the relationship
advisor
• A student is associated with at most one department via stud_dept

Many to one Many to many

Note: Some elements in A and B may not be mapped to any


elements in the other set

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 Many-to-One Relationships

 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

Many-to-Many Relationship E-R Diagram for a University Enterprise

 An instructor is associated with several (possibly 0) students via advisor


 A student is associated with several (possibly 0) instructors via advisor

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

 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
Reduction to Relation Schemas 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.31 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.32 ©Silberschatz, Korth and Sudarshan

Representing Entity Sets Representation of Entity Sets with Composite Attributes

 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

Representation of Entity Sets with Multivalued Attributes Representing Relationship Sets

 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

Redundancy of Schemas (Cont.) UML

 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

ER vs. UML Class Diagrams ER vs. UML Class Diagrams


ER Diagram Notation Equivalent in UML

* 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

 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.43 ©Silberschatz, Korth and Sudarshan Database System Concepts - 7th Edition 6.44 ©Silberschatz, Korth and Sudarshan

You might also like