Beruflich Dokumente
Kultur Dokumente
Lecture 2
Last Lecture
Enhanced ER Model
Any questions???
This Lecture
A relation consists of
Relation Schema = relation name + {name of each field: domain of each field} COURSE (course_no: integer, title: string, credits: integer, year: integer, semester: integer)
Example
Integrity constraint is a rule (or check) that is enforced by the DBMS to ensure that incorrect data is not stored in the database
Domain constraints (domain of a field) Key Constraints (UNIQUE & PRIMARY KEY) Foreign Key Constraints (FOREIGN KEY) Table Constraints (constraints within tables) Assertions (constraints between multiple tables)
Domain constraints: specify that each attribute A must be an atomic value from the domain of A. Atomic value: That is, the value is non divisible into components
32-3789
17-2489 54-5680 WP-1268
12342
22495 54356 24322
Toyota
Nissan Toyota Mitsubishi
Corolla
Sunny Vannette Galant
2000
1989 1990 2001
We can designate an attribute(s) as a foreign key(s) Foreign key(s) attribute(s) always refer to attribute(s) of the same or another entity Foreign keys enforce referential integrity constraints
Many relational DBMSs support most of the constraints described above. However, many applications require more advanced features for specifying integrity constraints.
Balance of the account should be greater than 0 In SQL, CHECK constraint can be used
For example: An employees salary should not exceed his/her managers salary Such constraints can be using specific language features such as triggers and assertions
Logical Database Design is the process of converting the E-ER Model to the Relational Model There are a set of conversion rules that can be applied
Relational
Relation
STUDENT
Relational Attributes
name
name
For example,
EMPLOYEE
fullname
surname
firstname
EMPLOYEE
surfirstname name
For example,
EMPLOYEE
a has id ADDRESS
id
ADDRESS
eid
For example,
A R B
B
For example,
ARTIST
yr_ created id creates OBJECTS
id
OBJECT
id
yr_created
name
CREATES
ARTIST
DateCreated
name creates
id
ART-OBJECT
ART_OBJECT
For example,
STUDENT
id
STUDENT
MIDDLE_NAMES
id
middle-name
id
middle names
pkB
A r C
pkA pkB
pkC pkD
D
pkC
pkD
a2
C
ISA
an
S1
S2
Sm
C is a super class with primary key, PK(C) = k Attributes of C = Attrs(C) = {k, a1, , an} S1, S2, , Sm are subclasses of C
Create a relation L for superclass C such that Attrs(L) = {k, a1, a2, , an} and PK(L) = k For each Si, create a relation Li such that Attrs(Li) = {k} U Attrs(Si) and PK(Li) = k
Relation L for class C Relation Li for each subclass Si Foreign key link from PK(Li) to PK(L) EQUIJOIN between Li and L to obtain all attributes of Li Option 1 works for all constraints disjoint, overlapping, total and partial.
For each subclass Si, create a new relation Li such that Attrs(Li) = Attrs(C) U Attrs(Li) and PK(Li) = k
The ISA relationship must be total (i.e. subclasses must cover the super class) If the subclasses are not disjoint, we keep multiple copies of Cs attributes values To obtain all entities in superclass C, we need to perform a full outer join with all relations Li
Create a single relation L with Attrs(L) = Attrs(C) U Attrs(S1) U U Attrs(Sm) U {t} such that PK(L) = k where t is type specifying which subclass the entity belongs if any. The specialization/generalization relationship must be disjoint
No EQUIJOIN or OUTER JOIN operation needed If subclasses have a lot of attributes, potential for many null values
Create a single relation L with Attrs(L) = Attrs(C) U Attrs(S1) U U Attrs(Sm) U {t1, t2, , tm} such that PK(L) = k where ti is a Boolean attribute indicating whether each tuple belongs to subclass Si. This relation allows overlapping constraints for specialization/generalization relationship
When having multilevel specialization (or generalization) hierarchy, we do not need to follow the same mapping option. We can use different mapping options for different parts of the hierarchy
R2
Entity C B
R1
PKA
R2
PKA PKB
PKB PKc
PKB
C
PKA
PKC
Entity A
R2
Entity C B
PKA
R2
PKB PKA
C
PKB PKc
PKC
Summary