130-ER

Published on May 2016 | Categories: Documents | Downloads: 50 | Comments: 0 | Views: 405
of 89
Download PDF   Embed   Report

Comments

Content


® q
Entity-Relationship (ER) model
130-ER: 1
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Entity-Relationship (ER) model
x A model based on the perception of a real world that
consists of
• a set of objects called entities
• attributes of the entities
• relationships among those objects
x It’s a semantic model — captures the semantics
(meanings of interactions) of information stored in a
database
130-ER: 2
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Entity-Relationship diagrams
x The model can be represented graphically using
Entity-Relationship (ER) diagrams
x Here we use Chen Notation of ER diagram
x Alternatives include Crow’s feet notation and Unified
Modeling Language (UML) notation
130-ER: 3
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Entities
®
x An entity, or entity occurrence, is a “thing” or an
“object” in the real world that is distinguishable from
other objects
x Example: The following things in a school can be
modeled as entities:
• A student
• A teacher
• A classroom
• A course
• An assignment
• An examination
x Note that the three on the left are concrete and the
three on the right are abstract
130-ER: 4
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
More entity examples
x To model a bank, the followings can be entities:
• A savings account
• A customer
• A bank branch
• A current account
• A teller
• A transaction
x Which are concrete and which are abstract?
x Note the similarity with the object-oriented design
concept object
130-ER: 5
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Attributes
®
x Descriptive properties possessed by an entity
x Often are data items a database needs to keep
x Each attribute has a domain
x Domains specify the set of permitted values for
attributes
x Represented by ellipses in ER diagrams (examples will
be shown later)
130-ER: 6
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Attribute example
x Borrowing from our example on flat files, a savings
account can have the following attributes in their
corresponding domains:
SavingsAccount
Attribute Description Domain
accountNo account number 10-char. string
balance balance of account integer
name name of account owner 18-char. string
address address of account owner 64-char. string
x Note the similarity with the object-oriented design
concepts attribute
130-ER: 7
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Entity sets / Entity types
x Entities of the same kind and share the same set of
attributes
x Example:
• A savings account is an entity
• All savings accounts have attributes such as account
number and balance
• There can be many such savings accounts in a bank,
thus we can group them into the entity set or type
SavingsAccount
130-ER: 8
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
More entity set examples
x In a university, we can model a course as an entity (is it
concrete or abstract?)
x All courses have attributes such as course code, course
title, and name of instructor
x We can group all such courses into an entity set Course
x Note the similarity with the object-oriented design
concept class
130-ER: 9
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Entity sets in ER diagrams
x Entity sets are represented by rectangles
x Recall that attributes are represented by ellipses (well,
not always, you’ll know later)
x Lines link attributes to entity sets
accountNo
name address
balance
SavingsAccount
130-ER: 10
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Attributes revisited
x Formally, an attribute is a function that maps an entity
set to the attribute’s domain
x Applying the function to an entity (member of an entity
set) gives the value of the attribute (member of the
domain) for that particular entity
130-ER: 11
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Types of attributes
x Attributes can be:
• Simple or composite
• Single-valued or multivalued
• Derived from other attributes
• Null
130-ER: 12
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Simple and composite attributes
®
x Simple attributes cannot be divided into subparts
x Composite attributes can be divided into subparts
(which can be seen as other attributes)
x Example: accountNo can be seen as a simple attribute
of SavingsAccount if its digits cannot be broken down
into meaningful subparts
x Example: name can be seen as a composite attribute of
SavingsAccount, consisting of parts firstName,
middleInitial and lastName
130-ER: 13
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Simple attributes cannot be divided into subparts.
How do we call database operations
that cannot be divided into subparts?
130-ER: 14
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Composite attributes
x Composite attribute groups related parts of the
attribute together for cleaner modeling of entities
x Useful when sometimes we need to refer to the entire
attribute and sometimes to subparts only
x Question: How to model address of SavingsAccount as
a composite attribute and when will it be useful?
130-ER: 15
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Composite attributes: question
x The domain of accountNo of SavingsAccount is a
10-character string
x A n-character string can be seen as an array of n
characters
x Why don’t we model accountNo as a composite
attribute consisting of 10 subparts?
130-ER: 16
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Single-valued and
multivalued attributes
®
x A single-valued attribute is one that has only one value
x A multivalued attribute is one that can have more than
one value
x Example: accountNo of SavingsAccount is a
single-valued attribute if a savings account can have
only one account number
x Example: name of SavingsAccount can be a multivalued
attribute if more than one person can jointly own an
account
130-ER: 17
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Multivalued attributes drawn
x Multivalued attributes are represented by double ellipses
in an ER diagram
accountNo
name address
balance
SavingsAccount
130-ER: 18
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Multivalued = single-valued?
x A multivalued attribute can be seen as a set or list of
single-valued attributes
x For example, a multivalued attribute of strings can be
seen as an attribute whose domain is a set or list of
strings
x Why don’t we make all attributes single-valued by
making their domain sets or lists?
130-ER: 19
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
What’s the difference between
multivalued attributes and composite attributes?
130-ER: 20
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Derived attributes
®
x Attributes whose values can be deduced from the values
of other attributes
x Can be omitted without losing information
x Example: the attribute age of the entity Student can be
derived from the attribute dateOfBirth
x Example: the attribute numOwners of the entity
SavingsAccount can be derived from the multivalued
attribute name
130-ER: 21
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Derived attributes drawn
x Derived attributes are represented by dashed ellipses in
an ER diagram
Student
age
birthday name
sex
x Question: how to draw the ER diagram for the
numOwners example?
130-ER: 22
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
name address
accountNo balance
numOwner
SavingsAccount
130-ER: 23
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Null values
®
x An entity can have no value for an attribute
x The value of an attribute can be unknown or
non-applicable
x Such values are called null
x Example: the attribute address of SavingsAccount can
be null if the customer do not have an address
130-ER: 24
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Relationships
®
x Relationship, or relationship occurrence: association
among two or more entities
x These entities can be of the same type
x Formally,
Given entity sets E
1
, E
2
, . . . , E
n
, n ≥ 2
All relationships (e
1
, e
2
, . . . , e
n
) must satisfy the condition
e
i
∈ E
i
for all i ∈ {1, 2, . . . , n}
130-ER: 25
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Relationship example
x (HKU’s account, Liu Man On’s account) is a
relationship on payment
x Who is paying whom? HKU→Liu Man On or Liu Man
On→HKU?
x Interpretation of the relationship is left to the designer
x The interpretation can be specified using words.
Example: for Works-for relationships on entity sets
Employee, relationship can be described as (manager,
worker) pairs
130-ER: 26
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Descriptive attributes
x Relationships may have descriptive attributes
x Example: the attributes amount and transactionDate
can associate with a relationship about Transfer
x There is no standard way to write relationships with
descriptive attributes. In our example, we can use
(fromAccount, toAccount); amount, transactionDate
where the following is an instance:
(HKU’s account, Liu Man On’s account); HKD 500, 2002-01-03
130-ER: 27
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Relationship sets
x A set of relationships of the same type
x Each member is a relationship
x A mathematical relation on n ≥ 2 entity sets
x These entity sets do not need to be distinct
x Formally,
Given entity sets E
1
, E
2
, . . . , E
n
Then R is a relationship set if
R ⊆ {(e
1
, e
2
, . . . , e
n
)|∀i ∈ {1, 2, . . . , n}[e
i
∈ E
i
]}
130-ER: 28
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Relationship set example
x The following is a relationship set on payment of salary
(the first party in a relationship pays to the second):
SalaryPayment= {(HKU’s account, Liu Man On’s account),
(HKU’s account, Ng Heung Dao’s account),
(HKU’s account, Lee Sau Wai’s account)}
130-ER: 29
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Relationship set drawn
x Relationship sets are represented by diamonds in an ER
diagram
x Descriptive attributes, like ordinary attributes, are
represented by ellipses
x Lines link relationship sets to entity sets
x Lines also link relationship sets to descriptive attributes
130-ER: 30
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Relationship set drawn: example
name
accountNo address
OwnerInfo
accountNo balance
BalanceTable
OwnerBalance
130-ER: 31
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Relationship sets: question
x Is the following a relationship set? Note that the some
accounts appear more than once on the same position
of the tuples
ServicePayment= {(HKU’s account, Government’s account),
(HKU’s account, IBM’s account),
(Government’s account, HKU’s account),
(Government’s account, IBM’s account)}
130-ER: 32
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
On terminology
x The number of entity sets involved in a relationship is
called the degree or arity of the relationship
• degree=2: binary relationship
• degree=3: ternary relationship
x The entity sets E
1
, E
2
, . . . , E
n
are said to participate in
the relationship set R
130-ER: 33
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
More terminologies
x The participation of an entity set E in a relationship set
R is said to be
_
_
_
total
partial
_
_
_
if
_
_
_
every
only some
_
_
_
entity(s) in E
participates in some relationship in R
x Total participation of an entity set in a relationship set
is indicated by the use of double lines to connect them
together (example later)
x When the same entity set participates in a relationship
set more than once, the relationship set is recursive
130-ER: 34
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Entity sets, attributes, relationship sets,
which to use in my model?
130-ER: 35
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Entity sets or attributes:
the question
Earlier in the SavingsAccount example, we know that the
attribute name can be composite with parts firstName,
middleInitial and lastName.
Why don’t we make it an entity set with three attributes
and build a relationship set that associates members of
SavingsAccount with that of Name?
130-ER: 36
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Entity sets or attributes:
the graphical representation
Original →
Proposed

accountNo
name address
balance
SavingsAccount
Name
firstName
middleInitial
lastName
OwnerName
accountNo address
balance
SavingsAccount
130-ER: 37
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Entity sets or attributes:
discussion
x In the original scheme, it is implicitly assumed that an
entity associates with one (and only one?) name
x In the proposed scheme, one account can associate with
more than one name
x The proposed scheme is more general and supports joint
accounts
x The proposed scheme is not useful if joint accounts
need not be supported
130-ER: 38
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Entity sets or attributes: a case
x What should the key for the entity set Name be?
x Confusions may arise if two different people with exactly
the same first name, middle initial and last name open
separate savings accounts in the bank, and then one of
them change name
130-ER: 39
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Entity sets or attributes:
so how can I choose?
x Entity sets or attributes: there is no simple answer on
which to use
x The choice depends on the structure and semantics of
real-world objects and their interactions
130-ER: 40
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Earlier in the SavingsAccount example we know that
modeling people’s names as entities is more general and
allows joint accounts to be supported.
However, joint accounts can also be supported using
multivalued attributes.
So, what’s the difference?
130-ER: 41
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Entity sets vs.
multivalued attributes
x Practical systems do not support lists as domain types
x Indeed, the first normal form of database schema
specify that there should be no multivalued attributes
x Normal forms will be covered later
130-ER: 42
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Entity sets or relationship sets:
the question
x In a company, some employees manage departments
x Each department has a number of attributes (omitted)
x Each employee has a number of attributes (omitted)
x Each managed department has a budget
x The start date of the management has to be recorded in
the database
x Propose an ER model for the situation
130-ER: 43
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Entity sets or relationship sets:
a model
x Entity sets: Employee, Department
x Relationship set: Manages; associates Employee with
Department
x Descriptive attributes: startDate, budget
Employee Department
Manages
startDate budget
130-ER: 44
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Entity sets or relationship sets:
another model
x Entity sets: Employee, Department, ManagerAppt
x Relationship set: Manages; associates Employee,
Department, and ManagerAppt
x Attributes of ManagerAppt: startDate, budget
Employee Department
Manages
startDate ManagerAppt budget
130-ER: 45
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Entity sets or relationship sets:
a discussion
x The first model (uses relationship sets) implicitly assume
that each management has one budget and start date
x Data has to be duplicated if the same employee manages
more than one department with a common budget
x Appointment-related data need not be duplicated in the
second model (that uses entity sets)
x It require ternary relationships
x To choose, use a relationship set to describe an action
between entities
130-ER: 46
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Mapping constraints
x These are constraints the data items of a database must
conform
x Two of the most important types:
• Mapping cardinalities
• Existence dependencies
130-ER: 47
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Mapping cardinalities
®
x Also called cardinality ratio
x Express the number of entities to which another entity
can be associated via a relationship set
x Types:
• one-to-one
• one-to-many
• many-to-one
• many-to-many
130-ER: 48
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Mapping cardinalities: definitions
x A relationship set R that associates entity sets A and B
is called
_
¸
¸
¸
¸
¸
_
¸
¸
¸
¸
¸
_
one-to-one
one-to-many
many-to-one
many-to-many
_
¸
¸
¸
¸
¸
_
¸
¸
¸
¸
¸
_
if every entity in A can
associate with
_
¸
¸
¸
¸
¸
_
¸
¸
¸
¸
¸
_
at most one
any number of
at most one
any number of
_
¸
¸
¸
¸
¸
_
¸
¸
¸
¸
¸
_
entity(s) in B and
every entity in B can associate with
_
¸
¸
¸
¸
¸
_
¸
¸
¸
¸
¸
_
at most one
at most one
any number of
any number of
_
¸
¸
¸
¸
¸
_
¸
¸
¸
¸
¸
_
entity(s) in A.
130-ER: 49
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Mapping cardinalities drawn
x Recall that a line links a relationship set to an entity set
in an ER diagram
x A directed line from the relationship set to the entity set
specifies that the entity set participates on the left side
of a one-to-one or one-to-many relationship
x To memorize: the arrow is on the “one” side and
touches an entity set
130-ER: 50
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
One-to-one: example
x (x, y) ∈ SpouseOf if x ∈ Man, y ∈ Woman, and x is a
spouse of y
x The relationship set SpouseOf that associates entities
in the entity set Man with those in the entity set
Woman is one-to-one in a society practicing monogamy
(what’s “monogamy”?)
Men Women
SpouseOf
130-ER: 51
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
One-to-one: questions
x What if some people (entities) in the entity set Man are
single?
x Does every entity in the Man set have to participate in
some relationship?
x Don’t mix up the issue of total participation with that
of mapping cardinality
130-ER: 52
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
One-to-many: example
x (x, y) ∈ MotherOf if x, y ∈ Person and x is the biological
mother of y
x The relationship set MotherOf that associates two
entities in the entity set Person is one-to-many since a
woman (an entity in the entity set Person) can be a
mother of many people (entities in the entity set Person)
but a person can only have one biological mother
130-ER: 53
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
One-to-many:
graphics and question
x Use role indicators for a relationship set if the same
entity set is involved more than once
Person MotherOf
child
mother
x You’ve forgot those men in the Person entity set, they
don’t participate in any relationship! — Is this
statement true?
130-ER: 54
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Many-to-one: example
x (x, y) ∈ ChildOf if x ∈ Person, y ∈ Man, and x is a
biological child of y
x The relationship set ChildOf that associates entities in
the entity set Person with entities in the entity set Man
is many-to-one since a person (an entity in the entity
set Person) can be a (biological) child of only one man
(entities in the entity set Man) but a man can have any
number of children
130-ER: 55
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Many-to-one:
graphics and question
x “Many persons can be children of a single man”
Person
ChildOf
Man
x Can a one-to-many relationship set be transformed into
a many-to-one relationship set? If so, how?
130-ER: 56
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Many-to-many: example
x (x, y) ∈ FriendOf if x, y ∈ Person and y considers x as a
friend
x The relationship set FriendOf that associates two
entities in the entity set Person is many-to-many since a
person (an entity in the entity set Person) can be a
friend of many people (entities in the entity set Person)
Person
considers
considered
FriendOf
130-ER: 57
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Is an empty relationship set one-to-one,
one-to-many, many-to-one, or many-to-many?
130-ER: 58
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Existence dependencies
®
x If the existence of entity x depends on the existence of
entity y, then x is said to be existence dependent on y
x Deletion of y will cause the deletion of x
x y is called the dominant entity
x x is called the subordinate entity
x Existence dependent entity sets totally participates in
relationships
x Recall that total participation of an entity set is
represented by double lines connecting relationship sets
and entity sets in an ER diagram (examples later)
130-ER: 59
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Existence dependencies: examples
x The entity set SavingsAccount keeps information about
a savings account
x The entity set Deposits keeps information about all the
deposits made to a particular savings account
x The relationship set SavingsAcctDeposit associates
SavingsAccount with Deposits in a one-to-many manner
x Deletion of SavingsAccount will cause deletion of
Deposits
x Deletion of Deposits will not affect SavingsAccount
x SavingsAccount is dominant, Deposits is subordinate
130-ER: 60
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Earlier when entities were introduced,
we are told that
entities are distinguishable from each other.
How?
130-ER: 61
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Keys in ER diagram
x There is no special notation on ER diagrams to denote
sets of attributes as superkeys or candidate keys
x Primary keys of entity sets are underlined in an ER
diagram
name address
balance accountNo
SavingsAccount
130-ER: 62
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
All those keys relate to entity sets.
How about relationship sets?
130-ER: 63
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Relationship sets: finding keys
x Suppose E
1
, E
2
, . . . , E
n
participate in a relationship set R
x Let primaryKey(E) be the set of attributes that forms
the primary key of E
x Assume that the attribute names of all primary keys are
unique
x Assume that a
1
, a
2
, . . . , a
m
are descriptive attributes of R
130-ER: 64
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Superkeys for relationship sets
x Individual relationships of R can be described by
_
_
_
_
r∈{1,2,...,n}
primaryKey(E
r
)
_
_
_
_
_
_
_
_
r∈{1,2,...,m}
{a
r
}
_
_
_
x The following is a superkey of the relationship set R no
matter how many descriptive attributes are associated
with R:

r∈{1,2,...,n}
primaryKey(E
r
)
x Candidate key of R depends on the mapping
cardinalities of R
130-ER: 65
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Relationship sets: candidate keys
x Example: candidate keys for binary relationship sets:
• many-to-many: the union of primary keys of both
entity sets
• one-to-many, many-to-one: the primary key of the
entity set on the “many” side
• one-to-one: the primary key of either entity set
130-ER: 66
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Is it possible that we do not have a key?
130-ER: 67
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Weak entity sets
x The Deposits entity set shown in our earlier example
may contain attributes depositNumber, date, and
amount
x Deposit numbers are unique within an account
x Different accounts may associate with entities of
Deposits with the same deposit number
x Deposits to different accounts may have the same
values for depositNumber, date, and amount,
130-ER: 68
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
More on weak entity sets
x No superkey exist for the entity set Deposits
x Deposits is a weak entity set
x Entity sets which are not weak are strong
130-ER: 69
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Discriminators
x Deposit numbers are unique within an account ⇒ when
combined with the primary key of SavingsAccount,
entities of Deposits can be uniquely identified
x For a weak entity set X which is existence dependent on
another entity set Y , if we can find a set of X’s
attributes d such that primaryKey(Y ) ∪ d uniquely
identifies entities in X, d is called a discriminator of X
x Example: {depositNumber} is a discriminator of the
entity set Deposits
130-ER: 70
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
More on discriminators
x Loosely speaking, primaryKey(Y ) ∪ discriminator(X)
forms a candidate key of X
x Discriminators of weak entity sets are denoted by dotted
lines under the attribute names (examples later)
130-ER: 71
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Weak entity set representations
x Represented by double-rectangles in ER diagrams
x Relationships associating a weak entity set with its own
are identifying relationships
x Identifying relationship sets is denoted by double-lined
diamonds
x Recall that existence dependencies are represented by
double lines connecting relationship sets and entity sets
130-ER: 72
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Weak entity sets drawn
name
Deposits
address
balance accountNo
depositNumber
date
amount
SavingAcctDeposit
SavingsAccount
130-ER: 73
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Entities and entity sets in the ER model
are like objects and classes in OO design.
Are there more similarities?
130-ER: 74
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Extended ER features
x Some aspects of databases may be better expressed if
extensions to the basic ER model is available
• Specialization
• Generalization
• Attribute inheritance
• Aggregation
130-ER: 75
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Specialization
x Some entity sets model general concepts
x Some entity sets can be seen as a specialization of
another entity set that models a general concept
x Specialization shows the “is a” relationship between
entity sets
x If A is a specialization of B, then A is a B
130-ER: 76
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Specialization example
x The entity set Account may have only the attributes
accountNo and balance
x SavingsAccount may have the attribute interestRate
which extends that of Account
x CurrentAccount may have the attribute overdraftLimit
which extends that of Account
x SavingsAccount is an Account, and so is
CurrentAccount
130-ER: 77
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
More on specialization
x Attribute inheritance: Specialized entity sets inherit the
attributes of the more general entity set
x Top-down design: initial entity sets are designed and
refinements are made for specialization
130-ER: 78
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Generalization
x Bottom-up design: attributes of entity sets are designed
and common attributes are factored out into a common
entity
x If an entity set A is a generalization of entity set B, then
entity set B is a specialization of entity set A
x Can be seen as an inversion of specialization
x Shows the “is a” relationship between entity sets
x If B is a generalization of A, then A is a B
130-ER: 79
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
More on the “is a” relationship
x A hierarchy of entity sets are formed by the
specialization/generalization process
x Compare class hierarchies in object-oriented languages
such as C++ or Java
x Note the similarity with object-oriented design concepts
inheritance and subclassing
130-ER: 80
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Drawing the “is a” relationship
x Specialization–generalization are represented in an ER
diagram using a downward-pointing rectangle with the
word “ISA” in it
x The more general entity set is connected to the top side
of the triangle
x The more special entity sets are connected to the
bottom sides of the triangle
130-ER: 81
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
The “is a” relationship drawn
accountNo balance
interestRate overdraftLimit
CurrentAccount
Account
ISA
SavingsAccount
130-ER: 82
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Aggregation
x Sometimes we want to associate relationship sets with
entity sets or relationship sets
x In an ER diagram, connecting two relationship sets by a
line would cause ambiguity
x Aggregates are needed
x Represented in an ER diagram by enclosing a
relationship set and its entity sets in a box
130-ER: 83
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Aggregation example
x Using our previous example on employees managing
departments with budgets, suppose we want to
additionally model that:
• A division of the company has a number of attributes
(omitted)
• Each managed department reports to a division
x We need to build relationships between the Manages
relationship set and the entity set Division
130-ER: 84
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Aggregation drawn
startDate budget
Employee Department
Manages
Reports
Division
130-ER: 85
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Basic concepts
x ER diagram
x Entities
x Attributes
• simple vs. composite
• single-valued vs. multivalued
• derived
• null values
x Entity sets
x Relationships
• descriptive
attributes
• degree or arity
x Relationship sets
• recursive
• participation
130-ER: 86
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
More concepts
x Mapping constraints
• Mapping cardinalities
◦ one-to-one
◦ one-to-many
◦ many-to-one
◦ many-to-many
• Existence dependencies
◦ dominant entity
◦ subordinate entity
x Keys
x Weak entity sets
• Discriminators
x Specialization
x Generalization
x Aggregation
130-ER: 87
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems
Design issue summary
x Entity sets vs. attributes
x Entity sets vs. multivalued attributes
x Entity sets vs. relationship sets
130-ER: 88
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems

Let’s discuss what the normal forms are.
130-ER: 89
HKU CSIS0278[AB] 2002-2003
Introduction to Database Systems

Sponsor Documents

Recommended

No recommend documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close