Assume the following relational schema covering vehicle ownership data (forgive lack of key, or assume that all attributes form the key, for now). Name.

Slides:



Advertisements
Similar presentations
Schema Refinement: Normal Forms
Advertisements

Lecture 21 CS 157 B Revision of Midterm3 Prof. Sin-Min Lee.
CS 440 Database Management Systems Practice problems for normalization.
Review for Final Exam Lecture Week 14. Problems on Functional Dependencies and Normal Forms.
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.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Integrity Constraints.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Relational Normalization Theory. Limitations of E-R Designs Provides a set of guidelines, does not result in a unique database schema Does not provide.
CS Algorithm : Decomposition into 3NF  Obviously, the algorithm for lossless join decomp into BCNF can be used to obtain a lossless join decomp.
Instructor: Amol Deshpande  Data Models ◦ Conceptual representation of the data  Data Retrieval ◦ How to ask questions of the database.
Normalization DB Tuning CS186 Final Review Session.
Normalization DB Tuning CS186 Final Review Session.
Normal Form Design addendum by C. Zaniolo. ©Silberschatz, Korth and Sudarshan7.2Database System Concepts Normal Form Design Compute the canonical cover.
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 Functional Dependency and Normalization Informal design guidelines for relation schemas. Functional dependencies. Normal forms. Normalization.
Schema Refinement and Normalization Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems October 6, 2004 Some slide content.
Schema Refinement and Normalization Nobody realizes that some people expend tremendous energy merely to be normal. Albert Camus.
Databases 6: Normalization
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.
Database Design & ER Diagrams
Midterm 1 Concepts Relational Algebra (DB4) SQL Querying and updating (DB5) Constraints and Triggers (DB11) Unified Modeling Language (DB9) Relational.
©Silberschatz, Korth and Sudarshan7.1Database System Concepts Chapter 7: Relational Database Design First Normal Form Pitfalls in Relational Database Design.
Chapter 10 Functional Dependencies and Normalization for Relational Databases.
For Project 1, Deliverable 4, you will add referential integrity (FOREIGN KEY) constraints to existing tables, as well as composing general assertions.
Relational Database Design by Relational Database Design by Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING.
1 CSE 480: Database Systems Lecture 5: Relational Data Model.
DBMS Spring 2014 Database Integrity Sources: Security in Computing, Pfleeger and Pfleeger, Prentice Hall, 2003 Lecture Slides, CSE6243, MSU, Rayford B.
Normal Forms1. 2 The Problems of Redundancy Redundancy is at the root of several problems associated with relational schemas: Wastes storage Causes problems.
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.
BCNF & Lossless Decomposition Prof. Sin-Min Lee Department of Computer Science.
For Project 1, Deliverable 4, you will add referential integrity (FOREIGN KEY) constraints to existing tables, as well as composing general assertions.
Functional Dependencies and Normalization Jose M. Peña
For Project 1, Deliverable 4, you will add referential integrity (FOREIGN KEY) constraints to existing tables, as well as composing general assertions.
Final Exam Revision Instructor: Mohamed Eltabakh 1.
1 Functional Dependencies and Normalization Chapter 15.
IST 210 Normalization 2 Todd Bacastow IST 210. Normalization Methods Inspection Closure Functional dependencies are key.
1 Dept. of CIS, Temple Univ. CIS616/661 – Principles of Data Management V. Megalooikonomou Integrity Constraints (based on slides by C. Faloutsos at CMU)
CSC 411/511: DBMS Design Dr. Nan Wang 1 Schema Refinement and Normal Forms Chapter 19.
Constraints and Triggers. What’s IC? Integrity Constraints define the valid states of SQL-data by constraining the values in the base tables. –Restrictions.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 15.
Temple University – CIS Dept. CIS331– Principles of Database Systems V. Megalooikonomou Database Design and Normalization (based on notes by Silberchatz,Korth,
Database Management Systems, 3ed, R. Ramakrishnan and J. Gehrke1 Schema Refinement and Normal Forms Chapter 19.
ICS 421 Spring 2010 Relational Model & Normal Forms Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa 1/19/20101Lipyeow.
MIS 3053 Database Design And Applications The University Of Tulsa Professor: Akhilesh Bajaj Normal Forms Lecture 1 © Akhilesh Bajaj, 2000, 2002, 2003.
CS 338Database Design and Normal Forms9-1 Database Design and Normal Forms Lecture Topics Measuring the quality of a schema Schema design with normalization.
Ch 7: Normalization-Part 1
MIS3053 Database Design And Applications The University Of Tulsa Professor: Akhilesh Bajaj Normal Forms Lecture 2 © Akhilesh Bajaj, 2000, 2002, 2003,2004.
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.
Dorm Name PK Occupancy Dorm Name PK Occupancy HighResDorm StartDate HighResDorm StartDate LowResDorm StartDate WaterSensorID WaterOnLineDate ElecSensorID.
1 Dept. of CIS, Temple Univ. CIS661 – Principles of Data Management V. Megalooikonomou Database design and normalization (based on slides by C. Faloutsos.
Logical Database Design and Relational Data Model Muhammad Nasir
Normalization and FUNctional Dependencies. Redundancy: root of several problems with relational schemas: –redundant storage, insert/delete/update anomalies.
Chapter 14 Functional Dependencies and Normalization Informal Design Guidelines for Relational Databases –Semantics of the Relation Attributes –Redundant.
CSC 411/511: DBMS Design Dr. Nan Wang 1 Schema Refinement and Normal Forms Chapter 19.
Study group exercises In attendance: 1. Suppose you have a relation P ( A, B, C, D, E, F ), with functional dependencies (FDs) A  B, BCD  E, E  F Suppose.
CS411 Database Systems 08: Midterm Review Kazuhiro Minami 1.
Relational Database Design by Dr. S. Sridhar, Ph. D
Normalization Murali Mani.
INSTRUCTOR: MRS T.G. ZHOU
CSC 453 Database Systems Lecture
Chapter 7a: Overview of Database Design -- Normalization
CS4222 Principles of Database System
Presentation transcript:

Assume the following relational schema covering vehicle ownership data (forgive lack of key, or assume that all attributes form the key, for now). Name Addr SSN VRN Type Make Model (N) (A) (S) (V) (T) (Ma) (Mo) Owners A “mega” relation Individual persons, uniquely identified by SSN, are stored with their Name and Addr(ess), and are stored with information of the vehicles they own, where each vehicle is uniquely Identified by a Vehicle Registration Number (VRN), its Type (auto, truck, motorcycle), Manufacturer (aka Make), and Model. A sample of a database fitting this schema is below. N A S V T Ma Mo Fred Nashville Truck Ford Ranger Sri NewYork Car Toyota Camry GabrielNashville MotorCyHarley Hog Fred Nashville Car VW Bug Given your domain knowledge of vehicle ownership relationships in the real world, list functional dependencies that you believe should be asserted as true/required of this relational schema (and be enforced in the database). 1

Assume the following functional dependencies apply to the schema S  N, S  A, V  T, V  Ma, V  Mo, Mo  Ma, Mo  T, V  S Name Addr SSN VRN Type Make Model (N) (A) (S) (V) (T) (Ma) (Mo) N A S V T Ma Mo Fred Nashville Truck Ford Ranger Sri NewYork Car Toyota Camry GabrielNashville MotorCyHarley Hog Fred Nashville Car VW Bug Sri NewYork Car VW Bug * Mary LosAngeles Car Toyota Corolla * Fred Nshville Car Honda Accord * Which of the FDs above are not needed given (i.e., can be inferred from) the other FDs? Each of the final three rows cause a violation of at least one FD (given the earlier rows). Identify the FDs that are violated in each case. State the constraint implied by each FD in English. 2

Assume the following functional dependencies apply to the schema S  N, S  A, V  T, V  Ma, V  Mo, Mo  Ma, Mo  T, V  S Name Addr SSN VRN Type Make Model (N) (A) (S) (V) (T) (Ma) (Mo) N A S V T Ma Mo Fred Nashville Truck Ford Ranger Sri NewYork Car Toyota Camry GabrielNashville MotorCyHarley Hog Fred Nashville Car VW Bug Sri NewYork Car VW Bug (V  S) Mary LosAngeles Car Toyota Corolla ( V  Mo,V  S) Fred Nshville Car Honda Accord (S  A) Give an example FD that can be inferred from the FDs above (other than the ones crossed out). Give the key(s) of the relation above, as dictated by the FDs. Each vehicle associated with one owner (1..1) or at most one (0..1). Nothing about these FDs implies that a Person need be an owner (0..*) 3

S  N, S  A, V  Mo, Mo  Ma, Mo  T, V  S (or S  N, A ; Mo  Ma, T ; V  Mo, S) N A S V T Ma Mo Fred Nashville Truck Ford Ranger Sri NewYork Car Toyota Camry GabrielNashville MotorCyHarley Hog Fred Nashville Car VW Bug Give an example FD that can be inferred from the FDs above: e.g., V  A; V  N, V,Na  S, T,... Give the key(s) of the relation above, as dictated by the FDs. V is NOT on the right-hand side (RHS) of any FD. Thus, V must be part of any key (i.e., the only way to infer V is to be given V). Is V alone a key? Yes. Attribute closure of V is {V}  {V, Mo}  {V, Mo, Ma}  {V, Mo, Ma, T}  {V, Mo, Ma, T, S}  {V, Mo, Ma, T, S, N}  {V, Mo, Ma, T, S, N, A} V  MoMo  Ma V  SMo  T S  N S  A Are there any other (minimal) keys? Show a decomposition of the mega relation into BCNF relations using the FDs above 4

N A S V T Ma Mo N A S S V T Ma Mo S  N, A V  Mo, S Importance of lossless decomposition: obvious, don’t want to lose information Importance of dependency preservation: each FD constraint can be checked by looking within a single table/relation (i.e., efficiency) Mo Ma T V Mo S Mo  Ma, T A dependency preserving, lossless decomposition into BCNF relations (Probably) Preferred decomposition V  S V Mo V S ? ? denormalized V  SV  Mo Write CREATE TABLE statements for each of the three relations in the preferred decomposition 5

N A S V T Ma Mo Fred Nashville Truck Ford Ranger Sri NewYork Car Toyota Camry GabrielNashville MotorCyHarley Hog Fred Nashville Car VW Bug N A S Fred Nashville 123 Sri NewYork 234 GabrielNashville 345 S V Mo Ranger Camry Hog Bug T Ma Mo Truck Ford Ranger Car Toyota Camry MotorCyHarley Hog Car VW Bug CREATE TABLE Person ( Name VARCHAR(60) NOT NULL, Address VARCHAR(120) NOT NULL, SSN INTEGER PRIMARY KEY ); CREATE TABLE Description ( Model CHAR(20) PRIMARY KEY, Manufacturer CHAR(20) NOT NULL, Type CHAR(10) ); CREATE TABLE Vehicle ( SSN INTEGER, /* NOT NULL? */ VRN INTEGER PRIMARY KEY, Model CHAR(10) NOT NULL, FOREIGN KEY (SSN) REFERENCES Person ON DELETE NO ACTION ON UPDATE CASCADE FOREIGN KEY (Model) REFERENCES Description ON DELETE NO ACTION ON UPDATE CASCADE ); S  N, A V  Mo, S Mo Ma T V Mo S Mo  Ma, T N A S Give a UML diagram that is consistent with these Table definitions. 6

Person SSN PK, Name, Address Vehicle VRN PK Description Model PK Type, Manufacturer or * CREATE TABLE Person ( Name VARCHAR(60) NOT NULL, Address VARCHAR(120) NOT NULL, SSN INTEGER PRIMARY KEY ); CREATE TABLE Description ( Model CHAR(20) PRIMARY KEY, Manufacturer CHAR(20) NOT NULL, Type CHAR(10)); CREATE TABLE Vehicle ( SSN INTEGER, /* NOT NULL? */ VRN INTEGER PRIMARY KEY, Model CHAR(10) NOT NULL, FOREIGN KEY (SSN) REFERENCES Person ON DELETE NO ACTION ON UPDATE CASCADE FOREIGN KEY (Model) REFERENCES Description ON DELETE NO ACTION ON UPDATE CASCADE); 7

Study exercises 2. Suppose you have a relation P ( A, B, C, D, E, F ), with functional dependencies (FDs) A  B, BCD  E, E  F Suppose there are at most 2 different possible values for each of attributes A, C, and D. What is the maximum number of different values for attribute F 3. Suppose that you have a relation Q (A, B, C, D, E) with only one FD AB  CDE. Decompose Q into a set of relations, EACH of which is in BCNF, or state that Q is already in BCNF (and in either case, explain your answer, and in doing so, identify the key for each relation). 4. Suppose that you have a relation R (A, B, C, D, E, F) with FDs AB  CD and D  EF. Decompose R into a set of relations, EACH of which is in BCNF, or state that R is already in BCNF (and in either case, explain your answer, and in doing so, identify the key for each relation). 5. For the Book table (from the Book-seller database), give (a) all the FDs that you believe are enforced by the table definition, and (b) any FDs that you think should be enforced, but aren’t currently What are the limitations of the previous database design of vehicle/owner relationships?

6. Consider the relation Kwatts, Dorm, Floor#, Date, Time, Temp, Humidity, Occupancy, Weekday?, SensorID and FDs that are asserted as true of the relation 1) Dorm, Floor#  Occupancy 2) Date, Time  Temp, Humidity 3) Date  Weekday? 4) SensorID, Date, Time, Temp  Kwatts 5) Dorm, Floor#, Date, Time, Temp  Kwatts 6) SensorId  Dorm, Floor# 7) Dorm, Floor#  SensorId a) Give a minimal FD set (remove any FDs that need not be explicitly stated, but that are implied by the remaining FDs). If there is more than one such set, just give one of them. b) Give all keys for the relation c) Give a decomposition of the relation into BCNF tables. If the relation is already in BCNF then state so. If there is no dependency-preserving decomposition into BCNF tables then state so. 9