SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Downloaden Sie, um offline zu lesen
ECS-165A WQ’11 15
2. Conceptual Modeling using the
Entity-Relationship Model
Contents
• Basic concepts: entities and entity types, attributes and keys,
relationships and relationship types
• Entity-Relationship schema (aka ER diagram)
• Constraints on relationship types
• Design choices
• Enhanced Entity-Relationship model features
• Steps in designing an ER schema
• Translation of an ER schema to tables
Dept. of Computer Science UC Davis 2. Entity-Relationship Model
ECS-165A WQ’11 16
What does Conceptual Design include?
Ideas −→
High-level
design
−→
Relational
database
schema
−→
Relational
DBMS
• Entity-Relationship model is used in the conceptual design of
a database (
conceptual level, conceptual schema)
• Design is independent of all physical considerations
(DBMS, OS, . . . ).
Questions that are addressed during conceptual design:
– What are the entities and relationships of interest (mini-
world)?
– What information about entities and relationships among
entities needs to be stored in the database?
– What are the constraints (or business rules) that (must)
hold for the entities and relationships?
• A database schema in the ER model can be represented
pictorially
(Entity-Relationship diagram)
Dept. of Computer Science UC Davis 2. Entity-Relationship Model
ECS-165A WQ’11 17
Entity Types, Entity Sets, Attributes and Keys
• Entity: real-world object or thing with an independent
existence and which is distinguishable from other objects.
Examples are a person, car, customer, product, gene, book
etc.
• Attributes: an entity is represented by a set of attributes
(its descriptive properties), e.g., name, age, salary, price etc.
Attribute values that describe each entity become a major part
of the data eventually stored in a database.
• With each attribute a domain is associated, i.e., a set of
permitted values for an attribute. Possible domains are
integer, string, date, etc.
• Entity Type: Collection of entities that all have the same
attributes, e.g., persons, cars, customers etc.
• Entity Set: Collection of entities of a particular entity type at
any point in time; entity set is typically referred to using the
same name as entity type.
Dept. of Computer Science UC Davis 2. Entity-Relationship Model
ECS-165A WQ’11 18
Key attributes of an Entity Type
• Entities of an entity type need to be distinguishable.
• A superkey of an entity type is a set of one or more attributes
whose values uniquely determine each entity in an entity set.
• A candidate key of an entity type is a minimal (in terms of
number of attributes) superkey.
• For an entity type, several candidate keys may exist. During
conceptual design, one of the candidate keys is selected to be
the primary key of the entity type.
Dept. of Computer Science UC Davis 2. Entity-Relationship Model
ECS-165A WQ’11 19
Relationships, Relationship Types, and Relationship Sets
• Relationship (instance): association among two or more
entities, e.g.,
“customer ’Smith’ orders product ’PC42’ ”
• Relationship Type: collection of similar relationships
An n-ary relationship type R links n entity types E1, . . . , En.
Each relationship in a relationship set R of a relationship type
involves entities e1 ∈ E1, . . . , en ∈ En
R ⊆ {(e1, . . . , en) | e1 ∈ E1, . . . , en ∈ En}
where (e1, . . . , en) is a relationship.
• Degree of a relationship: refers to the number of entity types
that participate in the relationship type (binary, ternary, . . . ).
• Roles: The same entity type can participate more than once
in a relationship type.
reports_toEMPLOYEES
supervisor
subordinate
Role labels clarify semantics of a relationship, i.e., the way in
which an entity participates in a relationship.
; recursive relationship.
Dept. of Computer Science UC Davis 2. Entity-Relationship Model
ECS-165A WQ’11 20
• Relationship Attributes: A relationship type can have
attributes describing properties of a relationship.
“customer ’Smith’ ordered product ’PC42’ on January 11,
2005, for $2345”.
These are attributes that cannot be associated with
participating entities only, i.e., they make only sense in the
context of a relationship.
• Note that a relationship does not have key attributes! The
identification of a particular relationship in a relationship set
occurs through the keys of participating entities.
Dept. of Computer Science UC Davis 2. Entity-Relationship Model
ECS-165A WQ’11 21
Example of an Entity-Relationship Diagram
offers Price
SAddress
Chain
CAddress
CUSTOMERS
orders
Account PRODUCTS
SUPPLIERS
Quantity
FName LName Prodname
SName
Customers-Suppliers-Products Entity-Relationship Diagram
• Rectangles represent entity types
• Ellipses represent attributes
• Diamonds represent relationship types
• Lines link attributes to entity types and entity types to
relationship types
• Primary key attributes are underlined
• Empty Circle at the end of a line linking an attribute to
an entity type represents an optional (null) attribute (not
mentioned in textbook)
Not in the above diagram, but later in examples:
• Double Ellipses represent multi-valued attributes
Dept. of Computer Science UC Davis 2. Entity-Relationship Model
ECS-165A WQ’11 22
Constraints on Relationship Types
Limit the number of possible combinations of entities that
may participate in a relationship set. There are two types of
constraints: cardinality ratio and participation constraints
Very useful concept in describing binary relationship types. For
binary relationships, the cardinality ratio must be one of the
following types:
• Many-To-Many (default)
EMPLOYEES works in DEPARTMENTS
Meaning: An employee can work in many departments (≥ 0),
and a department can have several employees
• Many-To-One
DEPARTMENTSworks inEMPLOYEES
Meaning: An employee can work in at most one department
(≤ 1), and a department can have several employees.
Dept. of Computer Science UC Davis 2. Entity-Relationship Model
ECS-165A WQ’11 23
• One-To-Many
DEPARTMENTSworks inEMPLOYEES
Meaning: An employee can work in many departments (≥ 0),
but a department can have at most one employee.
• One-To-One
DEPARTMENTSworks inEMPLOYEES
Meaning: An employee can work in at most one department,
and a department can have at most one employee.
Dept. of Computer Science UC Davis 2. Entity-Relationship Model
ECS-165A WQ’11 24
Constraints on Relationship Types (cont.)
A many-one relationship type (and the counterpart one-many) is
also often called a functional relationship.
Cardinality ratio of a relationship can affect the placement of a
relationship attribute. E.g., in case of a many-one relationship
type, one can place a relationship attribute at a participating
entity type.
Participation constraint: specifies whether the existence of an
entity e ∈ E depends on being related to another entity via the
relationship type R.
• total: each entity e ∈ E must participate in a relationship,
it cannot exist without that participation (total participation
aka existence dependency).
EMPLOYEES works in DEPARTMENTS
• partial: default; each entity e ∈ E can participate in a
relationship
Dept. of Computer Science UC Davis 2. Entity-Relationship Model
ECS-165A WQ’11 25
Instead of a cardinality ratio or participation constraint, more
precise cardinality limits (aka degree constraints in textbook) can
be associated with relationship types:
(min , max )
E
1 1
1
(min , max )2 2
E2R
Each entity e1 ∈ E1 must participate in relationship set R at
least min1 and at most max1 times (analogous for e2 ∈ E2).
Frequently used cardinalities
Relationship (min1, max1) (min2, max2) pictorial notation
many-to-many (0, ∗) (0, ∗)
many-to-one (0, 1) (0, ∗)
one-to-one (0, 1) (0, 1)
Dept. of Computer Science UC Davis 2. Entity-Relationship Model
ECS-165A WQ’11 26
Design Choices for ER Conceptual Design
It is possible to define entities and their relationships in a number
of different ways (in the same model!).
• Should a real-world concept be modeled as an entity type,
attribute, or relationship type?
Is “Address” an attribute or an entity type? Decision depends
upon the use one wants to make of address information. If one
is interested in the structure, e.g., (City, Street, Zip-Code),
Address must be modeled as an entity type (or as a complex
attribute).
• Should a concept be modeled as an entity type or relationship
type?
offers
Price
SUPPLIERS PRODUCTS
Here a supplier cannot offer the same product for different
prices! Why?
Modeling price as an entity type resolves this problem:
offersSUPPLIERS PRODUCTS
PRICE Amount
Dept. of Computer Science UC Davis 2. Entity-Relationship Model
ECS-165A WQ’11 27
Enhanced ER Modeling Concepts
Although most properties of entities and relationships can be
expressed using the basic modeling constructs, some of them are
costly and difficult to express (and to understand). That’s why
there are some extensions to the ER model.
Subclasses, Superclasses, and Inheritance
• In some cases, an entity type has numerous subgroupings of
its entities that are meaningful and need to be represented
explicitly because of their significance to the DB application.
ISA
PERSON
GPA STUDENT Major
NameSSN
• Relationships and attributes of superclass are inherited to
subclass (in particular primary key attribute(s)); subclass can
have additional attributes and relationships
• An entity cannot exist merely by being a member of only a
subclass.
Dept. of Computer Science UC Davis 2. Entity-Relationship Model
ECS-165A WQ’11 28
Specialization
• Process of defining a set of subclasses of an entity type
(top-down)
ISA
EMPLOYEES
SocialSN
HOURLY_EMPS
AddressName
CONTRACT_EMPS
ContractnoHours Wages
HOURLY EMPS is a subclass of EMPLOYEES and
thus inherits its attributes and relationships (same for
CONTRACT EMPS).
Generalization:
• Reverse process of specialization (bottom-up); identify
common features of entity types and generalize them into
single superclass (including primary key!)
ISA
CAR TRUCK
Tonage
AxelsMaxSpeed
NoOfPassengers
VEHICLE
VehicleNo Price LicensePlate
Dept. of Computer Science UC Davis 2. Entity-Relationship Model
ECS-165A WQ’11 29
Constraints on Specialization
• disjointness and totality constraints
disjoint, total/partial: each entity in the superclass must/can
be in exactly one subclass
The disjointness constraint is indicated by the word “disjoint”
right next to the ISA triangle
The totality constraint is indicated by double lines leading
from the superclass to the ISA triangle
• overlapping constraints
overlapping, total (. . . must be in at least one subclass) In
this case, only double lines leading to the ISA triangle are
used.
overlapping, partial (. . . can be in at least one subclass)
• Note: special rules are required to propagate deletions from
superclass/subclass (implemented later).
Note that for generalization, each entity in the superclass must
belong to exactly one subclass
Dept. of Computer Science UC Davis 2. Entity-Relationship Model
ECS-165A WQ’11 30
Steps in Designing an Entity-Relationship Schema
[Step 1] Identify entity types (entity type vs. attribute)
[Step 2] Identify relationship types
[Step 3] Identify and associate attributes with entity and
relationship types
[Step 4] Determine attribute domains
[Step 5] Determine primary key attributes for entity types
[Step 6] Associate (refined) cardinality ratio(s) with
relationship types
[Step 7] Design generalization/specialization hierarchies
including constraints (includes natural language statements
as well)
Dept. of Computer Science UC Davis 2. Entity-Relationship Model
ECS-165A WQ’11 31
Translation of ER Schema into Tables
• An ER schema can be represented by a collection of tables
which represent contents of the database (instance).
• Primary keys allow entity types and relationship types to be
expressed uniformly as tables.
• For each entity and relationship type, a unique table can be
derived which is assigned the name of the corresponding entity
or relationship type.
• Each table has a number of columns that correspond to the
attributes and which have unique names. An attribute of a
table has the same domain as the attribute in the ER schema.
• Translating an ER schema into a collection of tables is the
basis for deriving a relational database schema from an ER
diagram.
Dept. of Computer Science UC Davis 2. Entity-Relationship Model
ECS-165A WQ’11 32
Translating Entity Types into Tables
• Given an entity type E1 with (atomic) attributes A1, . . . , An
and associated domains D1, . . . , Dn.
• Translation of the entity type CUSTOMERS into table
CUSTOMERS
FName LName CAddress Account
Michael Smith San Francisco 10,000
George Jones New York 2,000
Kent Clark Los Angeles -4,600
. . . . . . . . . . . .
In SQL:
create table Customers(
FName char(40),
LName char(40),
CAddress char(70),
Account real
);
• A row in such a table corresponds to an entity from the entity
set.
Dept. of Computer Science UC Davis 2. Entity-Relationship Model
ECS-165A WQ’11 33
Translating Relationship Types into Tables
• A many-many relationship type is represented as a table with
columns for the primary key attributes of the participating
entity types, and any descriptive attributes of the relationship
type.
Example: Relationship type offers
Prodname SName Price
PC42 Hal-Mart 2,100
MacIV Sears 2,500
. . . . . . . . .
Prodname and SName are the primary key attributes of the
entity types SUPPLIERS and PRODUCTS.
• Translation of one-many and many-one (functional) and one-
one relationship types into tables can be optimized
; no table for relationship type necessary!
Dept. of Computer Science UC Davis 2. Entity-Relationship Model
ECS-165A WQ’11 34
Translating Subclasses/Superclasses into Tables
• Method 1: Form a table for the superclass and form a table
for each subclass. Include the primary key attributes of the
superclass in each such table.
Example:
Employees(SocialSN, Name, Address)
Hourly_Emps(SocialSN, Hours, Wages)
Contract_Emps(SocialSN, ContractNo)
• Method 2: Form a table for each subclass and include all
attributes of the superclass.
Hourly_Emps(SocialSN, Name, Address, Hours, Wages)
Contract_Emps(SocialSN, Name, Address, Contractno)
Method 2 has no table for the superclass EMPLOYEES.
• Method 3: Use null values
Employees(SocialSN, Name, Address,
Hours, Wages, ContractNo)
Hourly employees will have a null value for ContractNo.
Contract employees will have null values for Hours and
Wages.
Dept. of Computer Science UC Davis 2. Entity-Relationship Model

Weitere ähnliche Inhalte

Was ist angesagt?

Database - Entity Relationship Diagram (ERD)
Database - Entity Relationship Diagram (ERD)Database - Entity Relationship Diagram (ERD)
Database - Entity Relationship Diagram (ERD)Mudasir Qazi
 
Entity Relationship Modelling
Entity Relationship ModellingEntity Relationship Modelling
Entity Relationship ModellingBhandari Nawaraj
 
E-R diagram in Database
E-R diagram in DatabaseE-R diagram in Database
E-R diagram in DatabaseFatiha Qureshi
 
Entity Relationship Diagram2
Entity Relationship Diagram2Entity Relationship Diagram2
Entity Relationship Diagram2sadeenedian08
 
ER model to Relational model mapping
ER model to Relational model mappingER model to Relational model mapping
ER model to Relational model mappingShubham Saini
 
Enhanced E-R diagram
Enhanced E-R diagramEnhanced E-R diagram
Enhanced E-R diagramMayank Jain
 
ER DIAGRAM TO RELATIONAL SCHEMA MAPPING
ER DIAGRAM TO RELATIONAL SCHEMA MAPPING ER DIAGRAM TO RELATIONAL SCHEMA MAPPING
ER DIAGRAM TO RELATIONAL SCHEMA MAPPING ARADHYAYANA
 
The entity relationship model
The entity relationship modelThe entity relationship model
The entity relationship modelyash patel
 
Entity Relationship Diagrams
Entity Relationship DiagramsEntity Relationship Diagrams
Entity Relationship Diagramssadique_ghitm
 
Er & eer to relational mapping
Er & eer to relational mappingEr & eer to relational mapping
Er & eer to relational mappingsaurabhshertukde
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship DiagramRakhi Mukherji
 

Was ist angesagt? (20)

10287 lecture5(2)
10287 lecture5(2)10287 lecture5(2)
10287 lecture5(2)
 
Entity relationship modelling
Entity relationship modellingEntity relationship modelling
Entity relationship modelling
 
Database - Entity Relationship Diagram (ERD)
Database - Entity Relationship Diagram (ERD)Database - Entity Relationship Diagram (ERD)
Database - Entity Relationship Diagram (ERD)
 
Entity Relationship Modelling
Entity Relationship ModellingEntity Relationship Modelling
Entity Relationship Modelling
 
Ch 3 E R Model
Ch 3  E R  ModelCh 3  E R  Model
Ch 3 E R Model
 
E-R diagram in Database
E-R diagram in DatabaseE-R diagram in Database
E-R diagram in Database
 
Entity Relationship Diagram2
Entity Relationship Diagram2Entity Relationship Diagram2
Entity Relationship Diagram2
 
ER MODEL
ER MODELER MODEL
ER MODEL
 
ER model to Relational model mapping
ER model to Relational model mappingER model to Relational model mapping
ER model to Relational model mapping
 
Enhanced E-R diagram
Enhanced E-R diagramEnhanced E-R diagram
Enhanced E-R diagram
 
ER DIAGRAM TO RELATIONAL SCHEMA MAPPING
ER DIAGRAM TO RELATIONAL SCHEMA MAPPING ER DIAGRAM TO RELATIONAL SCHEMA MAPPING
ER DIAGRAM TO RELATIONAL SCHEMA MAPPING
 
The entity relationship model
The entity relationship modelThe entity relationship model
The entity relationship model
 
E R Diagram
E R DiagramE R Diagram
E R Diagram
 
Revision ch 3
Revision ch 3Revision ch 3
Revision ch 3
 
Er diagram
Er diagramEr diagram
Er diagram
 
Entity Relationship Diagrams
Entity Relationship DiagramsEntity Relationship Diagrams
Entity Relationship Diagrams
 
ER-Model-ER Diagram
ER-Model-ER DiagramER-Model-ER Diagram
ER-Model-ER Diagram
 
Enhanced ER(database)
Enhanced ER(database)Enhanced ER(database)
Enhanced ER(database)
 
Er & eer to relational mapping
Er & eer to relational mappingEr & eer to relational mapping
Er & eer to relational mapping
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
 

Andere mochten auch

4.2.cappelli 06
4.2.cappelli 064.2.cappelli 06
4.2.cappelli 06ELIMENG
 
4.2.cappelli 06(3)
4.2.cappelli 06(3)4.2.cappelli 06(3)
4.2.cappelli 06(3)ELIMENG
 
2.2 keys
2.2 keys2.2 keys
2.2 keysELIMENG
 
0c960528cf0be4df8f000000(1)
0c960528cf0be4df8f000000(1)0c960528cf0be4df8f000000(1)
0c960528cf0be4df8f000000(1)ELIMENG
 
6 wordiness(1)
6 wordiness(1)6 wordiness(1)
6 wordiness(1)ELIMENG
 
Appraising for recognition & reward
Appraising  for recognition & reward Appraising  for recognition & reward
Appraising for recognition & reward charwakmba
 
[9] fashion camps
[9] fashion camps[9] fashion camps
[9] fashion campsELIMENG
 
4.2.cappelli 06(2)
4.2.cappelli 06(2)4.2.cappelli 06(2)
4.2.cappelli 06(2)ELIMENG
 
4.2.cappelli 06(1)
4.2.cappelli 06(1)4.2.cappelli 06(1)
4.2.cappelli 06(1)ELIMENG
 
6 wordiness
6 wordiness6 wordiness
6 wordinessELIMENG
 
02 chapter02
02 chapter0202 chapter02
02 chapter02ELIMENG
 

Andere mochten auch (20)

4.2.cappelli 06
4.2.cappelli 064.2.cappelli 06
4.2.cappelli 06
 
04
0404
04
 
4.2.cappelli 06(3)
4.2.cappelli 06(3)4.2.cappelli 06(3)
4.2.cappelli 06(3)
 
2.2 keys
2.2 keys2.2 keys
2.2 keys
 
0c960528cf0be4df8f000000(1)
0c960528cf0be4df8f000000(1)0c960528cf0be4df8f000000(1)
0c960528cf0be4df8f000000(1)
 
4 2(1)
4 2(1)4 2(1)
4 2(1)
 
6 wordiness(1)
6 wordiness(1)6 wordiness(1)
6 wordiness(1)
 
1aap
1aap1aap
1aap
 
Chapter iii
Chapter iiiChapter iii
Chapter iii
 
8
88
8
 
Chapter iii
Chapter iiiChapter iii
Chapter iii
 
5 6
5 65 6
5 6
 
Appraising for recognition & reward
Appraising  for recognition & reward Appraising  for recognition & reward
Appraising for recognition & reward
 
4 2
4 24 2
4 2
 
[9] fashion camps
[9] fashion camps[9] fashion camps
[9] fashion camps
 
4.2.cappelli 06(2)
4.2.cappelli 06(2)4.2.cappelli 06(2)
4.2.cappelli 06(2)
 
4.2.cappelli 06(1)
4.2.cappelli 06(1)4.2.cappelli 06(1)
4.2.cappelli 06(1)
 
6 wordiness
6 wordiness6 wordiness
6 wordiness
 
02 chapter02
02 chapter0202 chapter02
02 chapter02
 
5
55
5
 

Ähnlich wie 2 er

Ähnlich wie 2 er (20)

entity-relationship-diagram-chen-&-crow -model.ppt
entity-relationship-diagram-chen-&-crow -model.pptentity-relationship-diagram-chen-&-crow -model.ppt
entity-relationship-diagram-chen-&-crow -model.ppt
 
entityrelationshipmodel.pptx
entityrelationshipmodel.pptxentityrelationshipmodel.pptx
entityrelationshipmodel.pptx
 
Entity-Relationship Data Model
Entity-Relationship Data ModelEntity-Relationship Data Model
Entity-Relationship Data Model
 
ERD.ppt
ERD.pptERD.ppt
ERD.ppt
 
ERD.ppt
ERD.pptERD.ppt
ERD.ppt
 
ER MODEL.pptx
ER MODEL.pptxER MODEL.pptx
ER MODEL.pptx
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship Model
 
Entity relationship modelling - DE L300
Entity relationship modelling - DE L300Entity relationship modelling - DE L300
Entity relationship modelling - DE L300
 
Entityrelationshipmodel
EntityrelationshipmodelEntityrelationshipmodel
Entityrelationshipmodel
 
Database design
Database designDatabase design
Database design
 
18306_lec-2 (1).ppt
18306_lec-2 (1).ppt18306_lec-2 (1).ppt
18306_lec-2 (1).ppt
 
DBMS Class 3
DBMS Class 3DBMS Class 3
DBMS Class 3
 
ICT DBA3 09 0710 Model Data Objects.pdf
ICT DBA3 09 0710 Model Data Objects.pdfICT DBA3 09 0710 Model Data Objects.pdf
ICT DBA3 09 0710 Model Data Objects.pdf
 
Day 1 SQL.pptx
Day 1 SQL.pptxDay 1 SQL.pptx
Day 1 SQL.pptx
 
SQL.pptx
SQL.pptxSQL.pptx
SQL.pptx
 
ERD(2).ppt
ERD(2).pptERD(2).ppt
ERD(2).ppt
 
ER&EER models
ER&EER modelsER&EER models
ER&EER models
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship Model
 
er-models.pptx
er-models.pptxer-models.pptx
er-models.pptx
 
E-R model unit(Iv)
E-R model unit(Iv)E-R model unit(Iv)
E-R model unit(Iv)
 

Mehr von ELIMENG

Get started with dropbox
Get started with dropboxGet started with dropbox
Get started with dropboxELIMENG
 
07 chap3
07 chap307 chap3
07 chap3ELIMENG
 
6 friction fe
6 friction fe6 friction fe
6 friction feELIMENG
 
06 9 1_balboa
06 9 1_balboa06 9 1_balboa
06 9 1_balboaELIMENG
 
05 chap 4 research methodology and design(1)
05 chap 4 research methodology and design(1)05 chap 4 research methodology and design(1)
05 chap 4 research methodology and design(1)ELIMENG
 
05 chap 4 research methodology and design
05 chap 4 research methodology and design05 chap 4 research methodology and design
05 chap 4 research methodology and designELIMENG
 
3 organization of intel 8086
3 organization of intel 80863 organization of intel 8086
3 organization of intel 8086ELIMENG
 
3 optimum-design
3 optimum-design3 optimum-design
3 optimum-designELIMENG
 
02 determinate structures
02 determinate structures02 determinate structures
02 determinate structuresELIMENG
 
2 design-of-reinforce-concrete-beams
2 design-of-reinforce-concrete-beams2 design-of-reinforce-concrete-beams
2 design-of-reinforce-concrete-beamsELIMENG
 
02 chapter02(1)
02 chapter02(1)02 chapter02(1)
02 chapter02(1)ELIMENG
 

Mehr von ELIMENG (16)

Get started with dropbox
Get started with dropboxGet started with dropbox
Get started with dropbox
 
07 chap3
07 chap307 chap3
07 chap3
 
7 4
7 47 4
7 4
 
6 friction fe
6 friction fe6 friction fe
6 friction fe
 
06 3
06 306 3
06 3
 
06 9 1_balboa
06 9 1_balboa06 9 1_balboa
06 9 1_balboa
 
05 chap 4 research methodology and design(1)
05 chap 4 research methodology and design(1)05 chap 4 research methodology and design(1)
05 chap 4 research methodology and design(1)
 
05 chap 4 research methodology and design
05 chap 4 research methodology and design05 chap 4 research methodology and design
05 chap 4 research methodology and design
 
04 99
04 9904 99
04 99
 
3 organization of intel 8086
3 organization of intel 80863 organization of intel 8086
3 organization of intel 8086
 
3 optimum-design
3 optimum-design3 optimum-design
3 optimum-design
 
02 determinate structures
02 determinate structures02 determinate structures
02 determinate structures
 
2 design-of-reinforce-concrete-beams
2 design-of-reinforce-concrete-beams2 design-of-reinforce-concrete-beams
2 design-of-reinforce-concrete-beams
 
02 chapter02(1)
02 chapter02(1)02 chapter02(1)
02 chapter02(1)
 
2 ch3
2 ch32 ch3
2 ch3
 
2
22
2
 

2 er

  • 1. ECS-165A WQ’11 15 2. Conceptual Modeling using the Entity-Relationship Model Contents • Basic concepts: entities and entity types, attributes and keys, relationships and relationship types • Entity-Relationship schema (aka ER diagram) • Constraints on relationship types • Design choices • Enhanced Entity-Relationship model features • Steps in designing an ER schema • Translation of an ER schema to tables Dept. of Computer Science UC Davis 2. Entity-Relationship Model
  • 2. ECS-165A WQ’11 16 What does Conceptual Design include? Ideas −→ High-level design −→ Relational database schema −→ Relational DBMS • Entity-Relationship model is used in the conceptual design of a database (
  • 3. conceptual level, conceptual schema) • Design is independent of all physical considerations (DBMS, OS, . . . ). Questions that are addressed during conceptual design: – What are the entities and relationships of interest (mini- world)? – What information about entities and relationships among entities needs to be stored in the database? – What are the constraints (or business rules) that (must) hold for the entities and relationships? • A database schema in the ER model can be represented pictorially (Entity-Relationship diagram) Dept. of Computer Science UC Davis 2. Entity-Relationship Model
  • 4. ECS-165A WQ’11 17 Entity Types, Entity Sets, Attributes and Keys • Entity: real-world object or thing with an independent existence and which is distinguishable from other objects. Examples are a person, car, customer, product, gene, book etc. • Attributes: an entity is represented by a set of attributes (its descriptive properties), e.g., name, age, salary, price etc. Attribute values that describe each entity become a major part of the data eventually stored in a database. • With each attribute a domain is associated, i.e., a set of permitted values for an attribute. Possible domains are integer, string, date, etc. • Entity Type: Collection of entities that all have the same attributes, e.g., persons, cars, customers etc. • Entity Set: Collection of entities of a particular entity type at any point in time; entity set is typically referred to using the same name as entity type. Dept. of Computer Science UC Davis 2. Entity-Relationship Model
  • 5. ECS-165A WQ’11 18 Key attributes of an Entity Type • Entities of an entity type need to be distinguishable. • A superkey of an entity type is a set of one or more attributes whose values uniquely determine each entity in an entity set. • A candidate key of an entity type is a minimal (in terms of number of attributes) superkey. • For an entity type, several candidate keys may exist. During conceptual design, one of the candidate keys is selected to be the primary key of the entity type. Dept. of Computer Science UC Davis 2. Entity-Relationship Model
  • 6. ECS-165A WQ’11 19 Relationships, Relationship Types, and Relationship Sets • Relationship (instance): association among two or more entities, e.g., “customer ’Smith’ orders product ’PC42’ ” • Relationship Type: collection of similar relationships An n-ary relationship type R links n entity types E1, . . . , En. Each relationship in a relationship set R of a relationship type involves entities e1 ∈ E1, . . . , en ∈ En R ⊆ {(e1, . . . , en) | e1 ∈ E1, . . . , en ∈ En} where (e1, . . . , en) is a relationship. • Degree of a relationship: refers to the number of entity types that participate in the relationship type (binary, ternary, . . . ). • Roles: The same entity type can participate more than once in a relationship type. reports_toEMPLOYEES supervisor subordinate Role labels clarify semantics of a relationship, i.e., the way in which an entity participates in a relationship. ; recursive relationship. Dept. of Computer Science UC Davis 2. Entity-Relationship Model
  • 7. ECS-165A WQ’11 20 • Relationship Attributes: A relationship type can have attributes describing properties of a relationship. “customer ’Smith’ ordered product ’PC42’ on January 11, 2005, for $2345”. These are attributes that cannot be associated with participating entities only, i.e., they make only sense in the context of a relationship. • Note that a relationship does not have key attributes! The identification of a particular relationship in a relationship set occurs through the keys of participating entities. Dept. of Computer Science UC Davis 2. Entity-Relationship Model
  • 8. ECS-165A WQ’11 21 Example of an Entity-Relationship Diagram offers Price SAddress Chain CAddress CUSTOMERS orders Account PRODUCTS SUPPLIERS Quantity FName LName Prodname SName Customers-Suppliers-Products Entity-Relationship Diagram • Rectangles represent entity types • Ellipses represent attributes • Diamonds represent relationship types • Lines link attributes to entity types and entity types to relationship types • Primary key attributes are underlined • Empty Circle at the end of a line linking an attribute to an entity type represents an optional (null) attribute (not mentioned in textbook) Not in the above diagram, but later in examples: • Double Ellipses represent multi-valued attributes Dept. of Computer Science UC Davis 2. Entity-Relationship Model
  • 9. ECS-165A WQ’11 22 Constraints on Relationship Types Limit the number of possible combinations of entities that may participate in a relationship set. There are two types of constraints: cardinality ratio and participation constraints Very useful concept in describing binary relationship types. For binary relationships, the cardinality ratio must be one of the following types: • Many-To-Many (default) EMPLOYEES works in DEPARTMENTS Meaning: An employee can work in many departments (≥ 0), and a department can have several employees • Many-To-One DEPARTMENTSworks inEMPLOYEES Meaning: An employee can work in at most one department (≤ 1), and a department can have several employees. Dept. of Computer Science UC Davis 2. Entity-Relationship Model
  • 10. ECS-165A WQ’11 23 • One-To-Many DEPARTMENTSworks inEMPLOYEES Meaning: An employee can work in many departments (≥ 0), but a department can have at most one employee. • One-To-One DEPARTMENTSworks inEMPLOYEES Meaning: An employee can work in at most one department, and a department can have at most one employee. Dept. of Computer Science UC Davis 2. Entity-Relationship Model
  • 11. ECS-165A WQ’11 24 Constraints on Relationship Types (cont.) A many-one relationship type (and the counterpart one-many) is also often called a functional relationship. Cardinality ratio of a relationship can affect the placement of a relationship attribute. E.g., in case of a many-one relationship type, one can place a relationship attribute at a participating entity type. Participation constraint: specifies whether the existence of an entity e ∈ E depends on being related to another entity via the relationship type R. • total: each entity e ∈ E must participate in a relationship, it cannot exist without that participation (total participation aka existence dependency). EMPLOYEES works in DEPARTMENTS • partial: default; each entity e ∈ E can participate in a relationship Dept. of Computer Science UC Davis 2. Entity-Relationship Model
  • 12. ECS-165A WQ’11 25 Instead of a cardinality ratio or participation constraint, more precise cardinality limits (aka degree constraints in textbook) can be associated with relationship types: (min , max ) E 1 1 1 (min , max )2 2 E2R Each entity e1 ∈ E1 must participate in relationship set R at least min1 and at most max1 times (analogous for e2 ∈ E2). Frequently used cardinalities Relationship (min1, max1) (min2, max2) pictorial notation many-to-many (0, ∗) (0, ∗) many-to-one (0, 1) (0, ∗) one-to-one (0, 1) (0, 1) Dept. of Computer Science UC Davis 2. Entity-Relationship Model
  • 13. ECS-165A WQ’11 26 Design Choices for ER Conceptual Design It is possible to define entities and their relationships in a number of different ways (in the same model!). • Should a real-world concept be modeled as an entity type, attribute, or relationship type? Is “Address” an attribute or an entity type? Decision depends upon the use one wants to make of address information. If one is interested in the structure, e.g., (City, Street, Zip-Code), Address must be modeled as an entity type (or as a complex attribute). • Should a concept be modeled as an entity type or relationship type? offers Price SUPPLIERS PRODUCTS Here a supplier cannot offer the same product for different prices! Why? Modeling price as an entity type resolves this problem: offersSUPPLIERS PRODUCTS PRICE Amount Dept. of Computer Science UC Davis 2. Entity-Relationship Model
  • 14. ECS-165A WQ’11 27 Enhanced ER Modeling Concepts Although most properties of entities and relationships can be expressed using the basic modeling constructs, some of them are costly and difficult to express (and to understand). That’s why there are some extensions to the ER model. Subclasses, Superclasses, and Inheritance • In some cases, an entity type has numerous subgroupings of its entities that are meaningful and need to be represented explicitly because of their significance to the DB application. ISA PERSON GPA STUDENT Major NameSSN • Relationships and attributes of superclass are inherited to subclass (in particular primary key attribute(s)); subclass can have additional attributes and relationships • An entity cannot exist merely by being a member of only a subclass. Dept. of Computer Science UC Davis 2. Entity-Relationship Model
  • 15. ECS-165A WQ’11 28 Specialization • Process of defining a set of subclasses of an entity type (top-down) ISA EMPLOYEES SocialSN HOURLY_EMPS AddressName CONTRACT_EMPS ContractnoHours Wages HOURLY EMPS is a subclass of EMPLOYEES and thus inherits its attributes and relationships (same for CONTRACT EMPS). Generalization: • Reverse process of specialization (bottom-up); identify common features of entity types and generalize them into single superclass (including primary key!) ISA CAR TRUCK Tonage AxelsMaxSpeed NoOfPassengers VEHICLE VehicleNo Price LicensePlate Dept. of Computer Science UC Davis 2. Entity-Relationship Model
  • 16. ECS-165A WQ’11 29 Constraints on Specialization • disjointness and totality constraints disjoint, total/partial: each entity in the superclass must/can be in exactly one subclass The disjointness constraint is indicated by the word “disjoint” right next to the ISA triangle The totality constraint is indicated by double lines leading from the superclass to the ISA triangle • overlapping constraints overlapping, total (. . . must be in at least one subclass) In this case, only double lines leading to the ISA triangle are used. overlapping, partial (. . . can be in at least one subclass) • Note: special rules are required to propagate deletions from superclass/subclass (implemented later). Note that for generalization, each entity in the superclass must belong to exactly one subclass Dept. of Computer Science UC Davis 2. Entity-Relationship Model
  • 17. ECS-165A WQ’11 30 Steps in Designing an Entity-Relationship Schema [Step 1] Identify entity types (entity type vs. attribute) [Step 2] Identify relationship types [Step 3] Identify and associate attributes with entity and relationship types [Step 4] Determine attribute domains [Step 5] Determine primary key attributes for entity types [Step 6] Associate (refined) cardinality ratio(s) with relationship types [Step 7] Design generalization/specialization hierarchies including constraints (includes natural language statements as well) Dept. of Computer Science UC Davis 2. Entity-Relationship Model
  • 18. ECS-165A WQ’11 31 Translation of ER Schema into Tables • An ER schema can be represented by a collection of tables which represent contents of the database (instance). • Primary keys allow entity types and relationship types to be expressed uniformly as tables. • For each entity and relationship type, a unique table can be derived which is assigned the name of the corresponding entity or relationship type. • Each table has a number of columns that correspond to the attributes and which have unique names. An attribute of a table has the same domain as the attribute in the ER schema. • Translating an ER schema into a collection of tables is the basis for deriving a relational database schema from an ER diagram. Dept. of Computer Science UC Davis 2. Entity-Relationship Model
  • 19. ECS-165A WQ’11 32 Translating Entity Types into Tables • Given an entity type E1 with (atomic) attributes A1, . . . , An and associated domains D1, . . . , Dn. • Translation of the entity type CUSTOMERS into table CUSTOMERS FName LName CAddress Account Michael Smith San Francisco 10,000 George Jones New York 2,000 Kent Clark Los Angeles -4,600 . . . . . . . . . . . . In SQL: create table Customers( FName char(40), LName char(40), CAddress char(70), Account real ); • A row in such a table corresponds to an entity from the entity set. Dept. of Computer Science UC Davis 2. Entity-Relationship Model
  • 20. ECS-165A WQ’11 33 Translating Relationship Types into Tables • A many-many relationship type is represented as a table with columns for the primary key attributes of the participating entity types, and any descriptive attributes of the relationship type. Example: Relationship type offers Prodname SName Price PC42 Hal-Mart 2,100 MacIV Sears 2,500 . . . . . . . . . Prodname and SName are the primary key attributes of the entity types SUPPLIERS and PRODUCTS. • Translation of one-many and many-one (functional) and one- one relationship types into tables can be optimized ; no table for relationship type necessary! Dept. of Computer Science UC Davis 2. Entity-Relationship Model
  • 21. ECS-165A WQ’11 34 Translating Subclasses/Superclasses into Tables • Method 1: Form a table for the superclass and form a table for each subclass. Include the primary key attributes of the superclass in each such table. Example: Employees(SocialSN, Name, Address) Hourly_Emps(SocialSN, Hours, Wages) Contract_Emps(SocialSN, ContractNo) • Method 2: Form a table for each subclass and include all attributes of the superclass. Hourly_Emps(SocialSN, Name, Address, Hours, Wages) Contract_Emps(SocialSN, Name, Address, Contractno) Method 2 has no table for the superclass EMPLOYEES. • Method 3: Use null values Employees(SocialSN, Name, Address, Hours, Wages, ContractNo) Hourly employees will have a null value for ContractNo. Contract employees will have null values for Hours and Wages. Dept. of Computer Science UC Davis 2. Entity-Relationship Model
  • 22. ECS-165A WQ’11 35 Summary of Conceptual Design • Conceptual design follows requirements analysis, yields a high level description of data to be stored (conceptual level). • ER model is a popular model for conceptual design, constructs are expressive, close to the way people think about applications; supported by many CASE tools. • Basic constructs are entities, relationships, and attributes • Some additional constructs: ISA hierarchies, cardinality ratios, . . . • There are many variations on ER model constructs . • Several kinds of integrity constraints can be expressed in the ER model: key constraints, structural constraints, constraints on specializations – Some of them can be expressed in SQL when translating entity and relationship types into tables – Not all constraints can be expressed in the ER model – Constraints play an important role in determining a good database design for an application domain. • ER design is subjective: There are many ways to model a given scenario! Analyzing alternative schemas is important! Entity type vs. attribute, entity type vs. relationship type, binary vs. n-ary relationship type, use of IS-A, generalization and specialization, . . . • Ensuring a good database design includes analyzing and further refining relational schema obtained through translating ER schema. Dept. of Computer Science UC Davis 2. Entity-Relationship Model