Download Logical Schema Design: Relational Data Model and more Exams Design in PDF only on Docsity!
Logical Schema Design:Logical Schema Design:The Relational Data ModelThe Relational Data ModelBasics of the Relational ModelFrom Conceptual to Logical Schema
Logical Schema DesignLogical Schema Design FU-Berlin, DBS I 2006, Hinze / Scholz
Select data model^ ^ Hierarchical data model: hierarchies of record typesmainframe oldie, still in use, outdated^ ^ Network data model: graph like data structures, still inuse, outdated^ ^ Relational data model: the most important one today^ ^ Object-Oriented data model: more flexible datastructures, less powerful data manipulation language^ ^ Object-Relational: the best of two worlds? Transform conceptual model into logical schema ofdata model^ ^ easy for Relational Data Model (RDM)^ ^ can be performed automatically (e.g. by Oracle Designer)
Logical Schema Design: Relational Data ModelLogical Schema Design: Relational Data Model FU-Berlin, DBS I 2006, Hinze / Scholz
Relation Schema R(A
, A, …, A 12
)n
notation sometimes R:{[A
, A, …, A 1 2
]}n^
^ Relation R
⊆^ dom(A
) x dom(A 1
) x … x dom(A 2
)n
^ Attribute set
R^ ={A^1
, A, …, A^2
}n
^ Degree of a relation: number of attributes ^ Example:^ Student(Fname, Name, Email, SID)Student
⊆^ string x string x string x number R (Student)^ ={Fname, Name, Email, SID
^ Database Schema is set of relation schemas
Logical Schema Design: Relational Data ModelLogical Schema Design: Relational Data Model FU-Berlin, DBS I 2006, Hinze / Scholz
Time-variant relations^ ^ Relations have
state at each point in time.
^ Integrity constraints on state part of DB schema Tuples (rows, records) ^ Not ordered ^ No duplicate tuples
(Relations are sets) ^ Null-values for some attributes possible ^ Distinguishable based on tuple values (key-concept)Different to object identification in o-o languages:there, each object has implicit identity,usually completely unrelated to its fields
Logical Schema Design: Relational Data ModelLogical Schema Design: Relational Data Model FU-Berlin, DBS I 2006, Hinze / Scholz
Candidate Key:superkey K of relation R such that if any attributeA^ ∈^ K is removed, the set of attributes K\A is not asuperkey of R.^ ^ Example: Student(Fname, Name, Email, SID)Candidate Keys: {Email}, {SID} Primary Key:arbitrarily designated candidate key^ ^ Example: Student(Fname, Name, Email, SID)Primary Key: {SID}
Important terms
Logical Schema Design: Relational Data ModelLogical Schema Design: Relational Data Model FU-Berlin, DBS I 2006, Hinze / Scholz
Foreign Key:set of attributes FK in relation schema R1 thatreferences relation R2 if:^ ^ Attributes of FK have the same domain as the attributesof primary key K
of R 2 2 ^ A value of FK in tuple t
in Reither occurs as a value of K 1 1
2
for some t
in R^ or is null. 2 2 ^ Example:R: Exercise(EID, Tutor, ExcerciseHours, Lecture)^1 R: Student(Fname, Name, Email, SID)^2 K={EID}, K^1
={SID} 2
Tutor is foreign key of Student (from Exercise ).
Important terms
Logical Schema Design: EntitiesLogical Schema Design: Entities FU-Berlin, DBS I 2006, Hinze / Scholz
Step 1: Transform entities^ ^ For each entity E create relation R with all attributes^ ^ Key attributes of E transform to keys of the relationRelational Schema:^ Movie(id, title, category, year, director, Price_per_day, length)
director Movie yearcategorytitle
id Price_per_daylength
Logical Schema Design: Weak EntitiesLogical Schema Design: Weak Entities FU-Berlin, DBS I 2006, Hinze / Scholz
Step 2: Transform weak entities^ ^ For each weak entity WE create relation R^ ^ Include all attributes of WE^ ^ Add key of identifying entity to weak entities key^ ^ Part of key is foreign keyRelational Schema:
Employee(eid)Child(cid, eid)
Note: weak entity and defining relationship
transformed together! Employee
has^
Child (0,*)^
(1,1)
eid^
cid
Logical Schema Design: RelationshipsLogical Schema Design: Relationships FU-Berlin, DBS I 2006, Hinze / Scholz
Step 3: Transform Relationships^ ^ For each 1:1-relationship between E1, E2 create relation R^ ^ Include all key attributes^ ^ Define as key: key of entity E1 or entity E2^ ^ Choose entity with total participation for key (drivinglicence) Relational Schema:
Country(CName)President(PName)has(CName, PName)
or^ has(Cname, PName) Country^
has^
President (1,1)^
(1,1)
PName
CName
Logical Schema Design: RelationshipsLogical Schema Design: Relationships FU-Berlin, DBS I 2006, Hinze / Scholz
Step 3: Transform Relationships^ ^ For each 1:N-relationship between E1, E2 create relation R^ ^ Include all key attributes^ ^ Define as key: key of N-side of relationshipRelational Schema:
Lecture(lnr)Lecturer(lid, name)hold(lnr,lid) Lecture^
hold^
Lecturer (1,1)^
(0,*)
lnr
lid name
Logical Schema Design: RelationshipsLogical Schema Design: Relationships FU-Berlin, DBS I 2006, Hinze / Scholz
Step 3: Transform Relationships^ ^ Include all relationship attributes in relation RRelational Schema:
require(preLNR, succLNR) Lecture Rename keys in recursive relationships
hold^
Lecturer (1,1)^
(0,N)
lnr
lid name
date Relational Schema:
Lecture(lnr)Lecturer(lid, name)hold(lnr,lid, date)
Lecture require predecessor
lnr successor (0,1)^
(0,*)
Logical Schema Design: RelationshipsLogical Schema Design: Relationships FU-Berlin, DBS I 2006, Hinze / Scholz
Step 3: Transform Relationships^ ^ For each n-ary relationship (n>2) create relation R^ ^ Include all key attributes^ ^ Define as key: keys from all numerously involved entities^ Lecturer
recommend
Textbook
(0,*)^
(1,) (0,) Lecture
lidname
ISBN lnr rating
title author
Relational Schema:
Lecture(lnr)Lecturer(lid, name)Textbook(ISBN, title, author)recommend(lid, lnr, ISBN, rating)
Logical Schema Design: GeneralizationLogical Schema Design: Generalization FU-Berlin, DBS I 2006, Hinze / Scholz
(1) Separate relation for each entity^ ^ Key in specialized relations:foreign key to general relation^ ^ Gathering data from different tables time consuming^ ^ Appropriate specialization prevents unnecessary dataaccess
B: C:
A:
aid A is-a is-a B C
c b
a
A(aid, a)B(aid, b)C(aid, c)
Logical Schema Design: GeneralizationLogical Schema Design: Generalization FU-Berlin, DBS I 2006, Hinze / Scholz
(2) Relations for specialization^ ^ Separate tables which includeA’s attributes^ ^ Separate keys for relations^ ^ Only valid for exhaustive specialization (no data in A only)^ ^ Time consuming data retrieval for non-distinctspecializations
AB:AC:
AB(aid, a, b)AC(aid, a, c)
aid A is-a is-a B C
c b
a