Database Management Systems Week 2
Database Management Systems Week 2
Modeling
• A database can be modeled as:
• a collection of entities,
• relationship among entities.
• An entity is an object that exists and is distinguishable
from other objects.
• Example: specific person, company, event, plant
• Entities have attributes
• Example: people have names and addresses
• 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
3
Relationship Sets
• A relationship is an association among several entities
Example:
Hayes borrower L-15
customer entity relationship set loan entity
• 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}
student
section
takes
7
Attributes
• An entity is represented by a set of attributes, that is
descriptive properties possessed by all members of an entity
set.
Example:
customer = (customer_id, customer_name,
customer_street, customer_city )
loan = (loan_number, amount )
• Domain – the set of permitted values for each attribute
• Attribute types:
• Simple and composite attributes.
• Single-valued and multi-valued attributes
• Example: multivalued attribute: phone_numbers
• Derived attributes
• Can be computed from other attributes
• Example: age, given date_of_birth
9
Composite Attributes
10
Mapping 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
12
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
13
Keys
• A super key of an entity set is a set of one or more
attributes whose values uniquely determine each
entity.
• A candidate key of an entity set is a minimal super
key
• customer_id is candidate key of customer
• account_number is candidate key of account
• Although several candidate keys may exist, one of
the candidate keys is selected to be the primary
key.
14
Example
• Identify possible super keys, candidate keys and
primary keys for the given entity set below:
E-R Diagrams
Roles
• 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
20
Cardinality 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.
• 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
21
One-To-Many Relationship
• In a 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
22
Many-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
23
Many-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
24
Cardinality Constraints
(a) (b)
(c) (d)
Existence Dependencies
• If the existence of entity x depends on the existence
of entity y, then x is said to be existence dependent
on y.
• y is a dominant entity (in example below, loan)
• x is a subordinate entity (in example below, payment)
Example
One-to-many
… … …
Book (including R)
37
Example (Cont.)
Many-to-many
… …
R
Book
38
Design Issues
• Use of entity sets vs. attributes
Choice mainly depends on the structure of the
enterprise being modeled, and on the semantics
associated with the attribute in question.
• Use of entity sets vs. relationship sets
Possible guideline is to designate a relationship set to
describe an action that occurs between entities
• Binary versus n-ary relationship sets
Although it is possible to replace any nonbinary (n-ary,
for n > 2) relationship set by a number of distinct binary
relationship sets, a n-ary relationship set shows more
clearly that several entities participate in a single
relationship.
• Placement of relationship attributes
39
1 1/1/2023 300
2 1/2/2023 300
L2 1 1/1/2023 300
L2 2 1/2/2023 300
P4 1 1/1/2023 300
P5 2 1/2/2023 300
Payment
45
L2 P4 1 1/1/2023 300
L2 P5 2 1/2/2023 300
• A weak entity set becomes a table that includes a column for the
primary key of the identifying strong entity set
Employee
Employee
Employee
55
Employee 4 1894546 2
Phone
57
1 Emma Johnson
2 Alex Harris
3 James Smith
Example: Bookstore
60