Docsity

Relational Database Design: Entity-Relationship Model and Functional Dependencies, Slides of Database Management Systems (DBMS)

Toggle sidebar
bg1
1
Relational Database Design
CPS 216
Advanced Database Systems
2
Announcements (January 20)
Review for Codd paper due tonight via email
Follow instructions on course Web site
Reading assignment for next week (Ailamaki et al.,
VLDB 2001) has been posted
Due next Wednesday night
Homework #1 assigned today
Expect an email regarding your DB2 account today
Due February 8 (in 2 ½ weeks)
Course project will be assigned next week
3
Database (schema) design
Understand the real-world domain being modeled
Specify it using a database design model
Design models are especially convenient for schema
design, but are not necessarily implemented by DBMS
Popular ones include
• Entity/Relationship (E/R) model
• Object Definition Language (ODL)
Translate the design to the data model of DBMS
Relational, XML, object-oriented, etc.
Apply database design theory to check the design
Create DBMS schema
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Relational Database Design: Entity-Relationship Model and Functional Dependencies and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

Relational Database Design

CPS 216

Advanced Database Systems

2

Announcements (January 20)

™ Review for Codd paper due tonight via email

ƒ Follow instructions on course Web site

™ Reading assignment for next week (Ailamaki et al.,

VLDB 2001) has been posted

ƒ Due next Wednesday night

™ Homework #1 assigned today

ƒ Expect an email regarding your DB2 account today ƒ Due February 8 (in 2 ½ weeks)

™ Course project will be assigned next week

3

Database (schema) design

™ Understand the real-world domain being modeled

™ Specify it using a database design model

ƒ Design models are especially convenient for schema design, but are not necessarily implemented by DBMS ƒ Popular ones include

  • Entity/Relationship (E/R) model
  • Object Definition Language (ODL)

™ Translate the design to the data model of DBMS

ƒ Relational, XML, object-oriented, etc.

™ Apply database design theory to check the design

™ Create DBMS schema

Entity-relationship (E/R) model

™ Historically very popular

ƒ Primarily a design model; not implemented by any major DBMS nowadays

™ Can think of as a “watered-down” object-oriented

design model

™ E/R diagrams represent designs

5

E/R example

™ Entity: a “thing,” like a record or an object

™ Entity set (rectangle): a collection of things of the same type, like a relation of tuples or a class of objects

™ Relationship: an association among two or more entities

™ Relationship set (diamond): a set of relationships of the same type; an association among two or more entity sets

™ Attributes (ovals): properties of entities or relationships, like attributes of tuples or objects

Students Courses

CID title

Enroll

SID name

6

ODL (Object Definition Language)

™ Standardized by ODMG (Object Data Management

Group)

ƒ Comes with a declarative query language OQL (Object Query Language) ƒ Implemented by OODBMS (Object-Oriented DataBase Management Systems)

™ Object oriented

™ Based on C ++^ syntax

™ Class declarations represent designs

Keys

™ A set of attributes K is a key for a relation R if

ƒ In no instance of R will two different tuples agree on all attributes of K

  • That is, K is a “tuple identifier” ƒ No proper subset of K satisfies the above condition
  • That is, K is minimal

™ Example: Student ( SID , name , age , GPA )

ƒ SID is a key of Student ƒ { SID , name } is not a key (not minimal)

11

Schema vs. data

™ Is name a key of Student?

Student SID name age GPA 142 Bart 10 2. 123 Milhouse 10 3. 857 Lisa 8 4. 456 Ralph 8 2. ... ... ... ...

12

More examples of keys

™ Enroll ( SID , CID )

™ Address ( street_address , city , state , zip )

™ Course ( CID , title , room , day_of_week , begin_time , end_time )

Usage of keys

™ More constraints on data, fewer mistakes

™ Look up a row by its key value

ƒ Many selection conditions are “key = value”

™ “Pointers”

ƒ Example: Enroll ( SID , CID )

  • SID is a key of Student
  • CID is a key of Course
  • An Enroll tuple “links” a Student tuple with a Course tuple ƒ Many join conditions are “key = key value stored in another table”

14

Motivation for a design theory

™ Why is this design is bad? ƒ This design has redundancy, because the name of a student is recorded multiple times, once for each course the student is taking

™ Why is redundancy bad?

™ How about a systematic approach to detecting and removing redundancy in designs? ƒ Dependencies, decompositions, and normal forms

SID name CID 142 Bart CPS 142 Bart CPS 857 Lisa CPS 857 Lisa CPS ... ... ...

15

Functional dependencies

™ A functional dependency (FD) has the form X → Y ,

where X and Y are sets of attributes in a relation R

™ X → Y means that whenever two tuples in R agree

on all the attributes in X , they must also agree on

all attributes of Y

X Y Z a b c a?? ... ... ...

X Y Z a b c a b? Must be b (^) ... ... ... Could be anything

Attribute closure

™ Given R , a set of FD’s F that hold in R , and a set of

attributes Z in R :

The closure of Z (denoted Z +^ ) with respect to F is

the set of all attributes functionally determined by Z

™ Algorithm for computing the closure

ƒ Start with closure = Z ƒ If X → Y is in F and X is already in the closure, then also add Y to the closure ƒ Repeat until no more attributes can be added

20

A more complex example

StudentGrade ( SID , name , email , CID , grade )

21

Example of computing closure

™ F includes: ƒ SID → name , email ƒ email → SID ƒ SID , CID → grade

™ { CID , email } +^ =?

™ email → SID ƒ Add SID ; closure is now { CID , email , SID }

™ SID → name , email ƒ Add name , email ; closure is now { CID , email , SID , name }

™ SID , CID → grade ƒ Add grade ; closure is now all the attributes in StudentGrade

Using attribute closure

Given a relation R and set of FD’s F

™ Does another FD X → Y follow from F?

ƒ Compute X +^ with respect to F ƒ If Y ⊆ X +^ , then X → Y follow from F

™ Is K a key of R?

23

Useful rules of FD’s

™ Armstrong’s axioms

ƒ Reflexivity: If Y ⊆ X , then X → Y ƒ Augmentation: If X → Y , then XZ → YZ for any Z ƒ Transitivity: If X → Y and Y → Z , then X → Z

™ Rules derived from axioms

ƒ Splitting: If X → YZ , then X → Y and X → Z ƒ Combining: If X → Y and X → Z , then X → YZ

24

Non-key FD’s

™ Consider a non-trivial FD X → Y where X is not a

super key

ƒ Since X is not a super key, there are some attributes (say Z ) that are not functionally determined by X

X Y Z a b c 1 a b c 2 ... ... ... The fact that a is always associated with b is recorded in multiple rows: redundancy!

Bad decomposition

™ Association between CID and grade is lost

™ Join returns more rows than the original relation

SID CID grade 142 CPS216 B- 142 CPS214 B 123 CPS216 B+ 857 CPS216 A+ 857 CPS230 A+ 456 CPS214 C ... ... ...

SID CID 142 CPS 142 CPS 123 CPS 857 CPS 857 CPS 456 CPS ... ...

SID grade 142 B- 142 B 123 B+ 857 A+ 857 A+ 456 C ... ...

29

Questions about decomposition

™ When to decompose

™ How to come up with a correct decomposition

30

An answer: BCNF

™ A relation R is in Boyce-Codd Normal Form if

ƒ For every non-trivial FD X → Y in R , X is a super key ƒ That is, all FDs follow from “key → other attributes”

™ When to decompose

ƒ As long as some relation is not in BCNF

™ How to come up with a correct decomposition

ƒ Always decompose on a BCNF violation )Then it is guaranteed to be a correct decomposition!

BCNF decomposition algorithm

™ Find a BCNF violation

ƒ That is, a non-trivial FD X → Y in R where X is not a super key of R

™ Decompose R into R 1 and R 2 , where

ƒ R 1 has attributes X ∪ Y ƒ R 2 has attributes X ∪ Z , where Z contains all attributes of R that are in neither X nor Y

™ Repeat until all relations are in BCNF

32

BCNF decomposition example

StudentGrade ( SID , name , email , CID , grade ) BCNF violation: SID → name , email

Student ( SID , name , email ) Grade ( SID , CID , grade )

BCNF BCNF

33

Another example

StudentGrade ( SID , name , email , CID , grade )