1 Triggers: Correction. 2 Mutating Tables (Explanation) The problems with mutating tables are mainly with FOR EACH ROW triggers STATEMENT triggers can.

Slides:



Advertisements
Similar presentations
CS 319: Theory of Databases
Advertisements

Schema Refinement: Normal Forms
Schema Refinement: Canonical/minimal Covers
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 16 Relational Database Design Algorithms and Further Dependencies.
Normalization 1 Instructor: Mohamed Eltabakh Part II.
Normalization Decomposition techniques for ensuring: Lossless joins Dependency preservation Redundancy avoidance We will look at some normal forms: Boyce-Codd.
Announcements Read 6.1 – 6.3 for Wednesday Project Step 3, due now Homework 5, due Friday 10/22 Project Step 4, due Monday Research paper –List of sources.
Logical Database Design (3 of 3) John Ortiz. Lecture 7Logical Database Design (2)2 Normalization  If a relation is not in BCNF or 3NF, we refine it by.
Schema Refinement and Normal Forms Given a design, how do we know it is good or not? What is the best design? Can a bad design be transformed into a good.
1 Design Theory. 2 Minimal Sets of Dependancies A set of dependencies is minimal if: 1.Every right side is a single attribute 2.For no X  A in F and.
Relational Normalization Theory. Limitations of E-R Designs Provides a set of guidelines, does not result in a unique database schema Does not provide.
©Silberschatz, Korth and Sudarshan Relational Database Design First Normal Form Pitfalls in Relational Database Design Functional Dependencies Decomposition.
Chapter 7: Relational Database Design. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Chapter 7: Relational Database Design First Normal.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 227 Database Systems I Design Theory for Relational Databases.
1 Design Theory. 2 Let U be a set of attributes and F be a set of functional dependencies on U. Suppose that X  U is a set of attributes. Definition:
Classroom Exercise: Normalization
Normalization DB Tuning CS186 Final Review Session.
Normalization DB Tuning CS186 Final Review Session.
Chapter 7: Relational Database Design. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Chapter 7: Relational Database Design First Normal.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. Relational Database Design - part 2 - Database Management Systems I Alex Coman,
CMSC424: Database Design Instructor: Amol Deshpande
Normal Form Design addendum by C. Zaniolo. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Normal Form Design Compute the canonical cover.
Design Theory.
1 Normalization Chapter What it’s all about Given a relation, R, and a set of functional dependencies, F, on R. Assume that R is not in a desirable.
1 CMSC424, Spring 2005 CMSC424: Database Design Lecture 9.
Decomposition By Yuhung Chen CS157A Section 2 October
Cs3431 Normalization. cs3431 Why Normalization? To remove potential redundancy in design Redundancy causes several anomalies: insert, delete and update.
Schema Refinement and Normalization Nobody realizes that some people expend tremendous energy merely to be normal. Albert Camus.
Cs3431 Normalization Part II. cs3431 Attribute Closure : Example Consider R (A, B, C, D, E) with FDs A  B, B  C, CD  E Does A  E hold ? (Is A  E.
Department of Computer Science and Engineering, HKUST Slide 1 7. Relational Database Design.
©Silberschatz, Korth and Sudarshan7.1Database System Concepts Chapter 7: Relational Database Design First Normal Form Pitfalls in Relational Database Design.
CS 405G: Introduction to Database Systems 16. Functional Dependency.
Database Systems Normal Forms. Decomposition Suppose we have a relation R[U] with a schema U={A 1,…,A n } – A decomposition of U is a set of schemas.
Relational Database Design by Relational Database Design by Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING.
Normal Forms1. 2 The Problems of Redundancy Redundancy is at the root of several problems associated with relational schemas: Wastes storage Causes problems.
CSCD34 - Data Management Systems - A. Vaisman1 Schema Refinement and Normal Forms.
Chapter 8: Relational Database Design First Normal Form First Normal Form Functional Dependencies Functional Dependencies Decomposition Decomposition Boyce-Codd.
Schema Refinement and Normalization. Functional Dependencies (Review) A functional dependency X  Y holds over relation schema R if, for every allowable.
Schema Refinement and Normal Forms Chapter 19 1 Database Management Systems 3ed, R.Ramakrishnan & J.Gehrke.
CS143 Review: Normalization Theory Q: Is it a good table design? We can start with an ER diagram or with a large relation that contain a sample of the.
SCUJ. Holliday - coen 1784–1 Schedule Today: u Normal Forms. u Section 3.6. Next u Relational Algebra. Read chapter 5 to page 199 After that u SQL Queries.
THIRD NORMAL FORM (3NF) A relation R is in BCNF if whenever a FD XA holds in R, one of the following statements is true: XA is a trivial FD, or X is.
Christoph F. Eick: Functional Dependencies, BCNF, and Normalization 1 Functional Dependencies, BCNF and Normalization.
1 Schema Refinement and Normal Forms Week 6. 2 The Evils of Redundancy  Redundancy is at the root of several problems associated with relational schemas:
Chapter 7: Relational Database Design. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Chapter 7: Relational Database Design First Normal.
Third Normal Form (3NF) Zaki Malik October 23, 2008.
Copyright, Harris Corporation & Ophir Frieder, The Process of Normalization.
Database Management Systems, 3ed, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 19.
Schema Refinement and Normalization Nobody realizes that some people expend tremendous energy merely to be normal. Albert Camus.
CS 405G: Introduction to Database Systems Instructor: Jinze Liu Fall 2009.
Functional Dependencies CIS 4301 Lecture Notes Lecture 8 - 2/7/2006.
CS 338Database Design and Normal Forms9-1 Database Design and Normal Forms Lecture Topics Measuring the quality of a schema Schema design with normalization.
CS542 1 Schema Refinement Chapter 19 (part 1) Functional Dependencies.
Database Management Systems, 3ed, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 19.
© D. Wong Functional Dependencies (FD)  Given: relation schema R(A1, …, An), and X and Y be subsets of (A1, … An). FD : X  Y means X functionally.
Chapter 8 Relational Database Design. 2 Relational Database Design: Goals n Reduce data redundancy (undesirable replication of data values) n Minimize.
1 CS 430 Database Theory Winter 2005 Lecture 8: Functional Dependencies Second, Third, and Boyce-Codd Normal Forms.
Normalization and FUNctional Dependencies. Redundancy: root of several problems with relational schemas: –redundant storage, insert/delete/update anomalies.
Normal Forms Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems June 18, 2016 Some slide content courtesy of Susan Davidson.
CSC 411/511: DBMS Design Dr. Nan Wang 1 Schema Refinement and Normal Forms Chapter 19.
Relational Database Design by Dr. S. Sridhar, Ph. D
CS 480: Database Systems Lecture 22 March 6, 2013.
3.1 Functional Dependencies
Dependency Preservation
Module 5: Overview of Normalization
Normalization cs3431.
Some slides are from Dr. Sara Cohen
Chapter 7a: Overview of Database Design -- Normalization
CS4222 Principles of Database System
Presentation transcript:

1 Triggers: Correction

2 Mutating Tables (Explanation) The problems with mutating tables are mainly with FOR EACH ROW triggers STATEMENT triggers can query/update/delete/etc the table that they are running on since they are run only at a point that processing is "complete" and the table is no longer mutating

3 Mutating Tables, Cont. So, the trigger of slide 13 in the trigger lesson is actually ok. It would not work if it was a FOR EACH ROW trigger Can you think of an action that could not be done with a trigger because of the mutating table problem? Or, can we always use a STATEMENT trigger to solve our problems?

4 Design Theory

5 Overview Starting Point: Set of function dependencies that describe real-world constraints Goal: Create tables that do not contain redundancies, so that –there is less wasted space –there is less of a chance to introduce errors in the the database

6 From Start to Goal (1) Armstrong's axioms defined, so that we can derive "implicit" functional dependencies Need to identify a key: –find a single key (algorithm from homework) –find all keys (algorithm taught in tirgul class) Both algorithms use as a subroutine an algorithm that computes the closure. In class a polynomial algorithm was given. Later today, a linear algorithm will be shown

7 From Start to Goal (2) Given a decomposition of a schema, need to be able to determine functional dependencies that hold on the sub-schemas. Two important characteristics of a decomposition: –lossless join (necessary, otherwise original relation cannot be recreated, even if tables are not modified) –dependency preserving: allows us to check that inserts/updates are correct without joining the relations

8 From Start to Goal (3) Check for a lossless join using the algorithm from class (with the a-s and b-s) Check for dependency preserving using an algorithm shown today Normal Forms: –3NF: Every dependency X->A must be (1) trivial, (2) X is a superkey or (3) A is an attribute of a key –BCNF: Every dependency X->A must be (1) trivial or (2) X is a key

9 From Start to Goal (3) Algorithm for decomposition to 3NF that has a lossless join and is dependency preserving uses a minimal cover (algorithm for minimal cover shown in class) Polynomial algorithm for decomposition to BCNF that has a lossless join not taught Question: Can you find a trivial decomposition to BCNF of any relation?

10 Compute Closure in Linear Time

11 Let U be a set of attributes and F be a set of functional dependencies on U. Suppose that X  U is a set of attributes. Definition: X + = { A | F X  A} We would like to compute X + Note: We use the symbol, not the symbol. Is there a difference? Closure of a Set of Attributes |=|= |=|= |_|_

12 Algorithm From Class Compute Closure(X, F) 1.X + := X 2.While there if a V  W in F such that (V  X + )and (W  X + ) do X + := X +  W 3. Return X + Complexity: |U|*|F|

13 A More Efficient Algorithm We start by creating a table, with a row for each FD and a column for each attribute. The table will have 2 additional columns called size and tail. In the row for a dependency X  Y, there will be the value true in each column corresponding to an attribute in X. The size column will contain the size of the set X. The tail column will contain Y.

14 Example Table F = {A → C, B → D, AD → E} ABCDESizeTail A → C 1 C B → D 1 D AD → E 2 E

15 Compute Closure(X, F, T) /* T is the table */ X + := X Q := X While Q is not empty A := Q.dequeue() for i=1..|F| if T[i, A]=true then T[i,size] := T[i, size] –1 if T[i,size]=0, then X + := X +  T[i,tail] Q := Q  T[i,tail]

16 Computing AB + ABCDESizeTail A → C 1 C B → D 1 D AD → E 2 E Start: X + = {A,B}, Q = {A, B}

17 Computing AB + ABCDESizeTail A → C 0 C B → D 1 D AD → E 1 E Iteration of A: X + = {A,B,C}, Q = {B,C}

18 Computing AB + Iteration of B: X + = {A,B,C,D}, Q = {C,D} ABCDESizeTail A → C 0 C B → D 0 D AD → E 1 E

19 Computing AB + Iteration of C: X + = {A,B,C,D}, Q = {D} ABCDESizeTail A → C 0 C B → D 0 D AD → E 1 E

20 Computing AB + Iteration of D: X + = {A,B,C,D,E}, Q = {E} ABCDESizeTail A → C 0 C B → D 0 D AD → E 0 E

21 Computing AB + Iteration of E: X + = {A,B,C,D,E}, Q = {} ABCDESizeTail A → C 0 C B → D 0 D AD → E 0 E

22 Complexity? To get an efficient algorithm, we assume that there are pointers from each “true” box in the table to the next “true” box in the same column. Complexity:O(|X| + |F|) ABCDESizeTail A → C 1 C B → D 1 D AD → E 2 E

23 Decompositions that Preserve Dependencies

24 Decompositions that Preserve Dependencies Problem: Suppose that we decompose R and then insert rows into the decomposition. Is it possible that the join of these rows will contradict a FD? Example: R = CSZ (city, street, zip-code) then, CS  Z, Z  C hold in R. Suppose we decompose into SZ and CZ. This is lossless. However, we can contradict CS  Z

25 Definitions We define  S (F) to be the set of dependencies X  Y in F + such that X and Y are in S. We say that a decomposition R 1...R n of R is dependency preserving if for all instances r of R that satisfy the FDs of R:  R 1 (F) U... U  R n (F) implies F Note that the other direction of implication clearly holds always. This definition implies and exponential algorithm to check if a decomposition is dependency preserving

26 Testing Dependency Preservation To check if the decomposition preserves X  Y: Z:=X while changes to Z occur do for i:=1..n do Z:=Z U ((Z R i ) + R i ) /* closure w.r.t. F */ Return true if Y is contained in Z Otherwise return false UU

27 Example Suppose R=ABCD and we have a decomposition {AB, BC, CD}, and dependencies {A  B, B  C, C  D, D  A}. Does this decomposition preserve D  A?