Designing Relational Databases

Slides:



Advertisements
Similar presentations
Schema Refinement: Normal Forms
Advertisements

Normalisation to 3NF Database Systems Lecture 11 Natasha Alechina.
Normalization Decomposition techniques for ensuring: Lossless joins Dependency preservation Redundancy avoidance We will look at some normal forms: Boyce-Codd.
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.
Chapter 7: Relational Database Design. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Chapter 7: Relational Database Design First Normal.
Chapter 7: Relational Database Design. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Chapter 7: Relational Database Design First Normal.
1 CMSC424, Spring 2005 CMSC424: Database Design Lecture 9.
Department of Computer Science and Engineering, HKUST Slide 1 7. Relational Database Design.
Boyce-Codd Normal Form By: Thanh Truong. Boyce-Codd Normal Form Eliminates all redundancy that can be discovered by functional dependencies But, we can.
Chapter 8: Relational Database Design First Normal Form First Normal Form Functional Dependencies Functional Dependencies Decomposition Decomposition Boyce-Codd.
©Silberschatz, Korth and Sudarshan7.1Database System Concepts Chapter 7: Relational Database Design First Normal Form Pitfalls in Relational Database Design.
Relational Database Design by Relational Database Design by Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING.
Chapter 8: Relational Database Design First Normal Form First Normal Form Functional Dependencies Functional Dependencies Decomposition Decomposition Boyce-Codd.
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.
Functional Dependencies An example: loan-info= Observe: tuples with the same value for lno will always have the same value for amt We write: lno  amt.
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.
Copyright, Harris Corporation & Ophir Frieder, The Process of Normalization.
Ch 7: Normalization-Part 1
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
Functional Dependency and Normalization
Advanced Normalization
CHAPTER 14 Basics of Functional Dependencies and Normalization for Relational Databases.
Schedule Today: Next After that Normal Forms. Section 3.6.
Schema Refinement and Normal Forms
Relational Database Design
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)
Database Design Dr. M.E. Fayad, Professor
Relational Database Design by Dr. S. Sridhar, Ph. D
Relational Database Design
CS 480: Database Systems Lecture 22 March 6, 2013.
Relational Database Design
Chapter 8: Relational Database Design
3.1 Functional Dependencies
Handout 4 Functional Dependencies
Advanced Normalization
Chapter 7: Relational Database Design
Chapter 15 Basics of Functional Dependencies and Normalization for Relational Databases.
Functional Dependencies and Normalization
Module 5: Overview of Normalization
Chapter 7: Relational Database Design
Schema Refinement What and why
Normalization Murali Mani.
Lecture #17: Schema Refinement & Normalization - Normal Forms
Functional Dependencies and Normalization
Functional Dependencies and Normalization
Functional Dependencies and Relational Schema Design
Relational Data Base Design in Practice
Normal Form: 4 & 5.
Normalization Part II cs3431.
Chapter 15 Basics of Functional Dependencies and Normalization for Relational Databases.
Functional Dependencies and Normalization
Lecture 8: Database Design
Normalization cs3431.
Some slides are from Dr. Sara Cohen
CS 405G: Introduction to Database Systems
Chapter 7: Relational Database Design
Instructor: Mohamed Eltabakh
Relational Database Design
Instructor: Mohamed Eltabakh
Chapter 7: Relational Database Design
Database Design Dr. M.E. Fayad, Professor
Database.
Chapter 7a: Overview of Database Design -- Normalization
Functional Dependencies and Normalization
Functional Dependencies and Normalization
Lecture 09: Functional Dependencies
CS4222 Principles of Database System
Presentation transcript:

Designing Relational Databases B.Ramamurthy 4/9/2019 B.ramamurthy

Problems with Simple Relations Repetition of information Inability to represent certain information Loss of information from decomposing relations 4/9/2019 B.ramamurthy

Example Consider a lending schema lending-schema (bname, bcity, assets, cname,loanNo, amt) when you want to insert a new loan do you have insert assets too? Ex: insert (Perry, Horseneck, 170000, Adams, l-13, 1500) 4/9/2019 B.ramamurthy

Example (contd.) How will you represent branch details if there was no loan in the branch. We will need null values. Null values are difficult to handle. 4/9/2019 B.ramamurthy

Solution : alternative design Decomposition Decompose lending-schema into branch-customer-schema(bcs) and customer-loan-schema(cls) bcs(bname, bcity, assets, cname) cls(cname, loanNo, amt) Is this decomposition correct? Lossless? 4/9/2019 B.ramamurthy

Decomposition bcs natural-join cls should result in our original lending but does it? For example, we cannot answer the question “Find all branches that have made loan < 100” on “lending-schema” will result in Mianus and Round Hill. But the same query on bcs joined with cls results in Mianus, Round Hill and Downtown. Some information was lost in decomposition that leads us to the incorrect answer. 4/9/2019 B.ramamurthy

How can we make decomposition lossless? Impose set of constraints (including functional dependencies). For example bname --> {bcity, assets} would have taken care of the problem above. 4/9/2019 B.ramamurthy

Formally Stating.. Let C be a set of constraints. A decomposition {R1, R2, .. Rn} of a relation scheme R is a lossless join for if all relations r on schema R that are legal under C, r = R1 ( r) join R2 ( r ) … join Rn ( r ) 4/9/2019 B.ramamurthy

Normalization using Functional Dependencies Using functional dependencies we can define several “normal forms” that represent good database deign. There are several normal forms : 1NF, 2NF, etc. We will cover 3NF and Boyce-Codd Normal Form (BCNF) 4/9/2019 B.ramamurthy

Desirable Properties Lossless-join decomposition Dependency preservation Lack of redundancy 4/9/2019 B.ramamurthy

BCNF A relation schema R is in BCNF with respect to a set of functional dependencies if for all functional dependencies in F+ of the form a-->b at least one of the following holds, a-->b is a trivial functional dependency (that is b is subset of a) a is superkey for schema R 4/9/2019 B.ramamurthy

Example customer-scheme(cname,cstreet,ccity) cname-->cstreet,ccity branch-scheme(banme, assets, bcity) bname-->asset,bcity loan-info-schema(bname, cname, loanNo, amt) loanNo-->amt,bname Is not BCNF 4/9/2019 B.ramamurthy

Solution Decompose loan-info-scheme into loan-schema (bname, loanNo, amt) Borrower-schema (cnmae, loanNo) 4/9/2019 B.ramamurthy

BCNF Decomposition result = {R} done = false Compute F+ while not done if there is a schema Ri that is not BCNF let a --> b be the non-trivial fn.dep in Ri s.t. a --> Ri is not in F+ and ab =0 result = (result -Ri)  (Ri-b)  (a,b) else done=true; 4/9/2019 B.ramamurthy

Lossless Decomposition If R is split into R1 and R2, for the decomposition to be loss less the at least one of the two should hold: R1  R2 --> R1 R1  R2 --> R2 4/9/2019 B.ramamurthy

Dependency Preservation When a relational schema D defined by functional dependency F is decomposed into Ri {i = 1,2,3 ..n}, each functional dependency should be testable by at least one of Ri. Formally, let F+ be the closure F and let F’+ be the closure of dependencies covered by Ri. F+ == F+’ for dependency preservation. 4/9/2019 B.ramamurthy

3NF : Third Normal Form BCNF is quite stringent that sometimes it may not be possible to cover all the functional dependencies after decomposition. 3NF solves this problem by relaxing the BCNF requirements as follows: 4/9/2019 B.ramamurthy

3NF : Definition A relation schema R is in BCNF with respect to a set of functional dependencies if for all functional dependencies in F+ of the form a-->b at least one of the following holds, a-->b is a trivial functional dependency (that is b is subset of a) a is superkey for schema R Each attribute A in b-->a is contained in a candidate key for R. 4/9/2019 B.ramamurthy

3NF : Algorithm Let Fc be the canonical cover of F. j = 0; for each dependency a-->b if none of schemes in Ri contains ab then j = j+1; Rj = ab; if none of the schemas contains a candidate key for R then j = j+ 1; Rj = any candidate key for R; return (Rj) 4/9/2019 B.ramamurthy

Examples : 7.2, 7.3, 7.8 4/9/2019 B.ramamurthy

Functional Dependencies (review) A functional dependency is a relationship between attributes Examples: Student ID determines Major: StuID => Major StuID => (Name, Major) (StuID, Course) => Grade Attribute(s) to the left of arrow called determinant(s) 4/9/2019 B.ramamurthy 3 3

Anomalies in a Relation (review) An anomaly is a weakness in the way a relation is set up Assume a single table representing student-courses (!) Consider the following table: Id Name Major Course-Id Course-Desc 45 Meyer CS CSE421 Operating Systems 56 Beaver CE CSE462 Database Concepts 23 Teller CE CSE506 Architecture This table has all three anomalies: insert, update, and delete 4/9/2019 B.ramamurthy 4 4

Insert, Update and Delete Anomalies (review) Insert anomaly is caused when a new course needs to be inserted that is not registered by a student Update anomaly caused when Major is updated in one row only for Id 45. Delete anomaly caused when Id 56 removed from the table; we lose a CSE course description Anomalies are avoided by splitting the offending relation into multiple relations (decomposition) 4/9/2019 B.ramamurthy 5 5

Fourth Normal Form (4NF) A multi-valued dependency exists when there are at least three attributes A, B, and C in a relation and for each value of A there is a well-defined set of values for B, and a well-defined set of values for C, but the set of values of B is independent of set C A relation is in 4NF if it is already in 3NF and has no multi-valued dependencies Every possible combination of the two multi-valued attributes have to be stored in the database thus leading to redundancy and consequent anomalies 4/9/2019 B.ramamurthy 8 10

Fourth Normal Form (4NF) - Example Course-Id Instructor Textbook MGS404 Clay Hansen MGS404 Clay Kroenke MGS404 Drake Hansen MGS404 Drake Kroenke By placing the multi-valued attributes in tables by themselves, we can convert the above to 4NF Change to: COURSE-INST (Course-Id, Instructor) COURSE-TEXT (Course-Id, Textbook) 4/9/2019 B.ramamurthy 8 11

Normal Forms 5NF 4NF BCNF 3NF 2NF 1NF 4/9/2019 B.ramamurthy

Homework #3 :Due date 4/11 in class : Hardcopy 1. Consider a scheme R (A,B,C,D,E) and the two set of functional dependencies. Are the two sets F1 and F2 equivalent? F1 : A-->B, AB--> C, D--> AC, D --> E F2 : A--> BC , D--> AE 2. Consider the schema R (A,B,C,D,E,F). AB--> C, C --> A, BC -->D, AC D--> B BE-->C, CE-->FA, CF-->BD, D-->EF a. Find the closure. b. Find the set candidate keys. Show all the steps. 4/9/2019 B.ramamurthy