ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of...

19
ICOM 5016 – Introduction to ICOM 5016 – Introduction to Database Systems Database Systems Lecture 4 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico, Mayagüez

Transcript of ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of...

Page 1: ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,

ICOM 5016 – Introduction to ICOM 5016 – Introduction to Database SystemsDatabase Systems

Lecture 4

Dr. Manuel Rodriguez

Department of Electrical and Computer Engineering

University of Puerto Rico, Mayagüez

Page 2: ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,

©Silberschatz, Korth and Sudarshan2.2Database System Concepts

ObjectivesObjectives

Describe Entity Relationship Model (E-R) Model

Entity Sets

Relationship Sets

Design Issues

Mapping Constraints

Keys

E-R Diagram

Extended E-R Features

Design of an E-R Database Schema

Reduction of an E-R Schema to Tables

Page 3: ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,

©Silberschatz, Korth and Sudarshan2.3Database System Concepts

Relationship Mapping CardinalitiesRelationship 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.

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

Page 4: ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,

©Silberschatz, Korth and Sudarshan2.4Database System Concepts

Mapping CardinalitiesMapping Cardinalities

One to one One to many

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

Page 5: ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,

©Silberschatz, Korth and Sudarshan2.5Database System Concepts

One-to-Many RelationshipOne-to-Many Relationship

e1

e2

e3

e4

e5

e6

e7

EMPLOYEE

r1

r2

r3

r4

r5

r6

r7

WORKS_FOR

d1

d2

d3

DEPARTMENT

Page 6: ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,

©Silberschatz, Korth and Sudarshan2.6Database System Concepts

Mapping Cardinalities Mapping Cardinalities

Many to one Many to many

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

Page 7: ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,

©Silberschatz, Korth and Sudarshan2.7Database System Concepts

Many-Many RelationshipMany-Many Relationship

e1

e2

e3

e4

e5

e6

e7

r1

r2

r3

r4

r5

r6

r7

d1

d2

d3

r8

r9

Page 8: ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,

©Silberschatz, Korth and Sudarshan2.8Database System Concepts

E-RE-R Diagram with a Ternary Relationship Diagram with a Ternary Relationship

Page 9: ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,

©Silberschatz, Korth and Sudarshan2.9Database System Concepts

Mapping Cardinalities affect ER DesignMapping Cardinalities affect ER Design

Can make access-date an attribute of account, instead of a relationship attribute, if each account can have only one customer

I.e., the relationship from account to customer is many to one, or equivalently, customer to account is one to many

Page 10: ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,

©Silberschatz, Korth and Sudarshan2.10Database System Concepts

E-R DiagramsE-R Diagrams

Rectangles represent entity sets.

Diamonds represent relationship sets.

Lines link attributes to entity sets and entity sets to relationship sets.

Ellipses represent attributes

Double ellipses represent multivalued attributes.

Dashed ellipses denote derived attributes.

Underline indicates primary key attributes (will study later)

Page 11: ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,

©Silberschatz, Korth and Sudarshan2.11Database System Concepts

E-R Diagram With Composite, Multivalued, and E-R Diagram With Composite, Multivalued, and Derived AttributesDerived Attributes

Page 12: ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,

©Silberschatz, Korth and Sudarshan2.12Database System Concepts

Relationship Sets with AttributesRelationship Sets with Attributes

Page 13: ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,

©Silberschatz, Korth and Sudarshan2.13Database System Concepts

RolesRoles

Entity sets of a relationship need not be distinct The labels “manager” and “worker” are called roles; they specify how

employee entities interact via the works-for relationship set.

Roles are indicated in E-R diagrams by labeling the lines that connect diamonds to rectangles.

Role labels are optional, and are used to clarify semantics of the relationship

Page 14: ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,

©Silberschatz, Korth and Sudarshan2.14Database System Concepts

Cardinality ConstraintsCardinality Constraints

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.

E.g.: One-to-one relationship: A customer is associated with at most one loan via the relationship

borrower

A loan is associated with at most one customer via borrower

Page 15: ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,

©Silberschatz, Korth and Sudarshan2.15Database System Concepts

One-To-Many RelationshipOne-To-Many Relationship

In the one-to-many relationship a loan is associated with at most one customer via borrower, a customer is associated with several (including 0) loans via borrower

Page 16: ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,

©Silberschatz, Korth and Sudarshan2.16Database System Concepts

Many-To-One RelationshipsMany-To-One Relationships

In a many-to-one relationship a loan is associated with several (including 0) customers via borrower, a customer is associated with at most one loan via borrower

Page 17: ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,

©Silberschatz, Korth and Sudarshan2.17Database System Concepts

Many-To-Many RelationshipMany-To-Many Relationship

A customer is associated with several (possibly 0) loans via borrower

A loan is associated with several (possibly 0) customers via borrower

Page 18: ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,

©Silberschatz, Korth and Sudarshan2.18Database System Concepts

Participation of an Entity Set in a Participation of an Entity Set in a Relationship SetRelationship Set

Total participation (indicated by double line): every entity in the entity set participates in at least one relationship in the relationship set

E.g. participation of loan in borrower is total

every loan must have a customer associated to it via borrower

Partial participation: some entities may not participate in any relationship in the relationship set

E.g. participation of customer in borrower is partial

Page 19: ICOM 5016 – Introduction to Database Systems Lecture 4 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,

©Silberschatz, Korth and Sudarshan2.19Database System Concepts

Alternative Notation for Cardinality Alternative Notation for Cardinality LimitsLimits

Cardinality limits can also express participation constraints