Lectures 12: Design Theory I

Slides:



Advertisements
Similar presentations
1 Introduction to Database Systems CSE 444 Lectures 8 & 9 Database Design April 16 & 18, 2008.
Advertisements

Functional Dependencies and Relational Schema Design.
©Silberschatz, Korth and Sudarshan7.1Database System Concepts Chapter 7: Relational Database Design First Normal Form Pitfalls in Relational Database Design.
Lecture 09: Functional Dependencies. Outline Functional dependencies (3.4) Rules about FDs (3.5) Design of a Relational schema (3.6)
Functional Dependencies. FarkasCSCE 5202 Reading and Exercises Database Systems- The Complete Book: Chapter 3.1, 3.2, 3.3., 3.4 Following lecture slides.
Functional Dependencies. Outline Functional dependencies (3.4) Rules about FDs (3.5) Design of a Relational schema (3.6)
© D. Wong Ch. 3 (continued)  Database design problems  Functional Dependency  Keys of relations  Decompositions based on Functional Dependency.
CS411 Database Systems Kazuhiro Minami 04: Relational Schema Design.
CSC 411/511: DBMS Design Dr. Nan Wang 1 Schema Refinement and Normal Forms Chapter 19.
1 CS122A: Introduction to Data Management Lecture #13: Relational DB Design Theory (II) Instructor: Chen Li.
Lecture 11: Functional Dependencies
Functional Dependency and Normalization
Design Theory for Relational Databases
Schedule Today: Next After that Normal Forms. Section 3.6.
COP4710 Database Systems Relational Design.
Schema Refinement and Normal Forms
Database Management Systems (CS 564)
CS411 Database Systems 08: Midterm Review Kazuhiro Minami 1.
Module 5: Overview of Database Design -- Normalization
Normalization First Normal Form (1NF) Boyce-Codd Normal Form (BCNF)
CPSC-310 Database Systems
1st, 2nd, 3rd Normal Forms Boyce-Codd Normal Form
Database Design Dr. M.E. Fayad, Professor
Relational Database Design by Dr. S. Sridhar, Ph. D
Chapter 8: Relational Database Design
3.1 Functional Dependencies
Handout 4 Functional Dependencies
Problems in Designing Schema
Schema Refinement and Normalization
Schema Refinement and Normalization
Lecture 6: Design Theory
Faloutsos & Pavlo SCS /615 Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications Lecture #16: Schema Refinement & Normalization.
Module 5: Overview of Normalization
Schema Refinement What and why
Normalization Murali Mani.
Lecture #17: Schema Refinement & Normalization - Normal Forms
Functional Dependencies and Normalization
1st, 2nd, and 3rd Normal Forms
Cse 344 May 16th – Normalization.
Functional Dependencies and Relational Schema Design
Introduction to Database Systems CSE 444 Lectures 8 & 9 Database Design October 12 & 15, 2007.
Lecture 09: Functional Dependencies, Database Design
Normalization Part II cs3431.
Lecture 8: Database Design
Decomposition and Higher Forms of Normalization
Functional Dependencies
Lecture 07: E/R Diagrams and Functional Dependencies
Lecture 21: Intro to Transactions & Logging III
Normalization cs3431.
CS 405G: Introduction to Database Systems
Instructor: Mohamed Eltabakh
CSE544 Data Modeling, Conceptual Design
Lectures 13: Design Theory II
1st, 2nd, and 3rd Normal Forms
Lecture 22: Intro to Transactions & Logging IV
Schema Refinement and Normal Forms
Chapter 19 (part 1) Functional Dependencies
Schema Refinement and Normalization
Relational Database Design
Lectures 2: Introduction to SQL 1
Anomalies Boyce-Codd Normal Form 3rd Normal Form
Lecture 08: E/R Diagrams and Functional Dependencies
Database Design Dr. M.E. Fayad, Professor
Lecture 6: Functional Dependencies
Lecture 11: Functional Dependencies
Chapter 7a: Overview of Database Design -- Normalization
Functional Dependencies and Normalization
Lecture 09: Functional Dependencies
CS4222 Principles of Database System
Presentation transcript:

Lectures 12: Design Theory I Professor Xiannong Meng Spring 2018 Lecture and activity contents are based on what Prof Chris Ré used in his CS 145 in the fall 2016 term with permission

Today’s Lecture Normal forms & functional dependencies ACTIVITY: Finding FDs Finding functional dependencies Closures, superkeys & keys ACTIVITY: The key or a key?

1. Normal forms & functional dependencies

What you will learn about in this section Overview of design theory & normal forms Data anomalies & constraints Functional dependencies ACTIVITY: Finding FDs

Design Theory Design theory is about how to represent your data to avoid anomalies. It is a mostly mechanical process Tools can carry out routine portions We have a notebook implementing all algorithms! We’ll play with it in the activities!

Normal Forms 1st Normal Form (1NF) = All tables are flat 2nd Normal Form = disused Boyce-Codd Normal Form (BCNF) 3rd Normal Form (3NF) 4th and 5th Normal Forms = see text books DB designs based on functional dependencies, intended to prevent data anomalies Our focus

1NF Constraint: Types must be atomic! 1st Normal Form (1NF) Student Courses Mary CS145 CS229 Joe CS106 Student Courses Mary {CS145,CS229} Joe {CS145,CS106} … Violates 1NF. In 1st NF 1NF Constraint: Types must be atomic!

Data Anomalies & Constraints

Constraints Prevent (some) Anomalies in the Data A poorly designed database causes anomalies: Student Course Room Mary CS145 B01 Joe Sam .. If the course is in only one room, e.g., one section, the table contains redundant information!

Constraints Prevent (some) Anomalies in the Data A poorly designed database causes anomalies: Student Course Room Mary CS145 B01 Joe C12 Sam .. If we update the room number for one tuple, we get inconsistent data = an update anomaly

Constraints Prevent (some) Anomalies in the Data A poorly designed database causes anomalies: Student Course Room .. If everyone drops the class, we lose what room the class is in! = a delete anomaly

Constraints Prevent (some) Anomalies in the Data A poorly designed database causes anomalies: Student Course Room Mary CS145 B01 Joe Sam .. Similarly, we can’t reserve a room without students = an insert anomaly … CS229 C12

Constraints Prevent (some) Anomalies in the Data Is this form better? Redundancy? Update anomaly? Delete anomaly? Insert anomaly? Student Course Mary CS145 Joe Sam .. Course Room CS145 B01 CS229 C12 Develop theory to understand why this design may be better and how to find this decomposition…

Functional Dependencies

Functional Dependency Def: Let A,B be sets of attributes We write A  B or say A functionally determines B if, for any tuples t1 and t2: t1[A] = t2[A] implies t1[B] = t2[B] and we call A  B a functional dependency A->B means that “whenever two tuples agree on A then they agree on B.”

A Picture Of FDs Defn (again): Given attribute sets A={A1,…,Am} and B = {B1,…Bn} in R, A1 … Am B1 Bn

A Picture Of FDs Defn (again): Given attribute sets A={A1,…,Am} and B = {B1,…Bn} in R, The functional dependency A B on R holds if for any ti,tj in R: A1 … Am B1 Bn ti tj

A Picture Of FDs Defn (again): Given attribute sets A={A1,…,Am} and B = {B1,…Bn} in R, The functional dependency A B on R holds if for any ti,tj in R: ti[A1] = tj[A1] AND ti[A2]=tj[A2] AND … AND ti[Am] = tj[Am] A1 … Am B1 Bn ti tj If t1,t2 agree here..

A Picture Of FDs Defn (again): Given attribute sets A={A1,…,Am} and B = {B1,…Bn} in R, The functional dependency A B on R holds if for any ti,tj in R: if ti[A1] = tj[A1] AND ti[A2]=tj[A2] AND … AND ti[Am] = tj[Am] then ti[B1] = tj[B1] AND ti[B2]=tj[B2] AND … AND ti[Bn] = tj[Bn] A1 … Am B1 Bn ti tj If t1,t2 agree here.. …they also agree here!

FDs for Relational Schema Design High-level idea: why do we care about FDs? Start with some relational schema Find out its functional dependencies (FDs) Use these to design a better schema One which minimizes the possibility of anomalies

Functional Dependencies as Constraints Student Course Room Mary CS145 B01 Joe Sam .. A functional dependency is a form of constraint Holds on some instances not others. Part of the schema, helps define a valid instance. Note: The FD {Course} -> {Room} holds on this instance Recall: an instance of a schema is a multiset of tuples conforming to that schema, i.e., a table

Functional Dependencies as Constraints Note that: You can check if an FD is violated by examining a single instance; However, you cannot prove that an FD is part of the schema by examining a single instance. This would require checking every valid instance Student Course Room Mary CS145 B01 Joe Sam .. However, cannot prove that the FD {Course} -> {Room} is part of the schema

More Examples An FD is a constraint which holds, or does not hold on an instance: EmpID Name Phone Position E0045 Smith 1234 Clerk E3542 Mike 9876 Salesrep E1111 E9999 Mary Lawyer

More Examples EmpID Name Phone Position E0045 Smith 1234 Clerk E3542 Mike 9876  Salesrep E1111 E9999 Mary Lawyer {Position}  {Phone}

More Examples EmpID Name Phone Position E0045 Smith 1234  Clerk E3542 1234  Clerk E3542 Mike 9876 Salesrep E1111 E9999 Mary Lawyer but not {Phone}  {Position}

ACTIVITY Find at least three FDs which hold on this instance: A B C D 1 2 4 3 6 5 8 7 { }  { }