RELATIONAL DATABASE DESIGN



Similar documents
COSC344 Database Theory and Applications. Lecture 9 Normalisation. COSC344 Lecture 9 1

Chapter 15 Basics of Functional Dependencies and Normalization for Relational Databases

Database Design and Normalization

CS 377 Database Systems. Database Design Theory and Normalization. Li Xiong Department of Mathematics and Computer Science Emory University

Chapter 5: Logical Database Design and the Relational Model Part 2: Normalization. Introduction to Normalization. Normal Forms.

Relational Database Design

DATABASE NORMALIZATION

Normalisation to 3NF. Database Systems Lecture 11 Natasha Alechina

Chapter 7: Relational Database Design

Databases -Normalization III. (N Spadaccini 2010 and W Liu 2012) Databases - Normalization III 1 / 31

Normalization in Database Design

Functional Dependency and Normalization for Relational Databases

Design of Relational Database Schemas

Normalization in OODB Design

Chapter 10. Functional Dependencies and Normalization for Relational Databases

Chapter 10. Functional Dependencies and Normalization for Relational Databases. Copyright 2007 Ramez Elmasri and Shamkant B.

Theory of Relational Database Design and Normalization

Normalization of Database

Schema Refinement, Functional Dependencies, Normalization

Database Management System

Database Design and Normal Forms

Database Normalization. Mohua Sarkar, Ph.D Software Engineer California Pacific Medical Center

MCQs~Databases~Relational Model and Normalization

Week 11: Normal Forms. Logical Database Design. Normal Forms and Normalization. Examples of Redundancy

Database Management Systems. Redundancy and Other Problems. Redundancy

normalisation Goals: Suppose we have a db scheme: is it good? define precise notions of the qualities of a relational database scheme

Introduction to normalization. Introduction to normalization

Announcements. SQL is hot! Facebook. Goal. Database Design Process. IT420: Database Management and Organization. Normalization (Chapter 3)

Normalization. Functional Dependence. Normalization. Normalization. GIS Applications. Spring 2011

If it's in the 2nd NF and there are no non-key fields that depend on attributes in the table other than the Primary Key.

Chapter 10 Functional Dependencies and Normalization for Relational Databases

Theory of Relational Database Design and Normalization

Schema Design and Normal Forms Sid Name Level Rating Wage Hours

Jordan University of Science & Technology Computer Science Department CS 728: Advanced Database Systems Midterm Exam First 2009/2010

Relational Database Design Theory

Introduction Decomposition Simple Synthesis Bernstein Synthesis and Beyond. 6. Normalization. Stéphane Bressan. January 28, 2015

Part 6. Normalization

Lecture 2 Normalization

DATABASE MANAGEMENT SYSTEMS. Question Bank:

C HAPTER 4 INTRODUCTION. Relational Databases FILE VS. DATABASES FILE VS. DATABASES

Schema Refinement and Normalization

CS143 Notes: Normalization Theory

Unit 3.1. Normalisation 1 - V Normalisation 1. Dr Gordon Russell, Napier University

Limitations of E-R Designs. Relational Normalization Theory. Redundancy and Other Problems. Redundancy. Anomalies. Example

C# Cname Ccity.. P1# Date1 Qnt1 P2# Date2 P9# Date9 1 Codd London Martin Paris Deen London

LiTH, Tekniska högskolan vid Linköpings universitet 1(7) IDA, Institutionen för datavetenskap Juha Takkinen

CSCI-GA Database Systems Lecture 7: Schema Refinement and Normalization

Normalisation 1. Chapter 4.1 V4.0. Napier University

Chapter 5: FUNCTIONAL DEPENDENCIES AND NORMALIZATION FOR RELATIONAL DATABASES

Database Systems Concepts, Languages and Architectures

Normalization. CIS 331: Introduction to Database Systems

BCA. Database Management System

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

Lecture Notes on Database Normalization

Relational Database Basics Review

Normalisation 6 TABLE OF CONTENTS LEARNING OUTCOMES

Functional Dependencies and Finding a Minimal Cover

Introduction to Databases, Fall 2005 IT University of Copenhagen. Lecture 5: Normalization II; Database design case studies. September 26, 2005

Database Constraints and Design


Bridge from Entity Relationship modeling to creating SQL databases, tables, & relations

A. TRUE-FALSE: GROUP 2 PRACTICE EXAMPLES FOR THE REVIEW QUIZ:

Boyce-Codd Normal Form

Database Design. Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB

Why Is This Important? Schema Refinement and Normal Forms. The Evils of Redundancy. Functional Dependencies (FDs) Example (Contd.)

DATABASE DESIGN: NORMALIZATION NOTE & EXERCISES (Up to 3NF)

Database Design and Normalization

Scheme G. Sample Test Paper-I

Data Modeling. Database Systems: The Complete Book Ch ,

Introduction to Database Systems. Normalization

Normalization. CIS 3730 Designing and Managing Data. J.G. Zheng Fall 2010

DBMS. Normalization. Module Title?

Normal forms and normalization

Lecture 6. SQL, Logical DB Design

Fundamentals of Database System

The process of database development. Logical model: relational DBMS. Relation

User Manual. for the. Database Normalizer. application. Elmar Jürgens

6.830 Lecture PS1 Due Next Time (Tuesday!) Lab 1 Out today start early! Relational Model Continued, and Schema Design and Normalization

Chapter 8. Database Design II: Relational Normalization Theory

Theory behind Normalization & DB Design. Satisfiability: Does an FD hold? Lecture 12

Relational Normalization: Contents. Relational Database Design: Rationale. Relational Database Design. Motivation

DATABASE SYSTEMS. Chapter 7 Normalisation

SQL Server. 1. What is RDBMS?

LOGICAL DATABASE DESIGN

Information Systems Analysis and Design CSC John Mylopoulos Database Design Information Systems Analysis and Design CSC340

Relational Database Concepts

Normalization. Normalization. First goal: to eliminate redundant data. for example, don t storing the same data in more than one table

SQL, PL/SQL FALL Semester 2013

IT2304: Database Systems 1 (DBS 1)

Optimum Database Design: Using Normal Forms and Ensuring Data Integrity. by Patrick Crever, Relational Database Programmer, Synergex

Introduction to Computing. Lectured by: Dr. Pham Tran Vu

Database Sample Examination

Objectives of Database Design Functional Dependencies 1st Normal Form Decomposition Boyce-Codd Normal Form 3rd Normal Form Multivalue Dependencies

Functional Dependencies

EECS 647: Introduction to Database Systems

An Algorithmic Approach to Database Normalization

Conceptual Design Using the Entity-Relationship (ER) Model

Transcription:

RELATIONAL DATABASE DESIGN g Good database design - Avoiding anomalies g Functional Dependencies g Normalization & Decomposition Using Functional Dependencies g 1NF - Atomic Domains and First Normal Form g 2NF - Partial Dependencies and Second Normal Form g 3NF - Transitive dependencies and Third Normal Form g 4NF - Multi-valued Dependencies and Fourth Normal Form g 5NF - Decomposition and non loss-less join g Benefits of Normalization 1 AVOIDING ANOMALIES - DATABASE CONSISTENCY How to avoid inconsistent/anomalous state in Integrity Constraints address/avoid anomalies that can occur during the Database Manipulation stage e.g. Referential integrities and foreign keys Normalization addresses/avoids anomalies that can occur during the Database Design stage - good database design 2

FUNCTIONAL DEPENDENCY Relations in the database should be legal under a given set of Functional Dependencies (FDs) Example: Name Telephone-number Article-number Price Attribute B (in relation F) is functionally dependent on attribute A (also in relation F) means: For each value of A, there is a unique value of B Written: A B Read: A functionally determines B or B is functionally dependent on A 3 FUNCTIONAL DEPENDENCY - continued We can extend the notion of functional dependence to multiple fields A1, A2,, Am B1, B2, Bn First-name, last-name Student-ID Full functional dependence (vs. partial functional dependence) is a functional dependence where there is not a functional dependence from a subset of the A1, A2,, Am to B1, B2,, Bn Normalization: decomposes the relations according to their FDs, to avoid anomalies (e.g. insertion, deletion, and update anomalies) Developed through a number of stages: 1NF, 2NF, 3NF, BCNF (Boyce Codd Normal Form), 4NF and 5NF 4

EXAMPLE O-O DATABASE SCHEMA Database of ships with potentially hazardous cargo entering the coastal water of some country () This is a portion of the schema Only major relationships are shown BANNED-OIL-TANKER (M) IS-A Country-Banning COUNTRY Name HULL# Has-Hull# (M) Has- Inspected Has-Name Ship- Inspected OIL-TANKER Commands Has- Captain (M) Has-Banned CAPTAIN INSPECTION Has-Name PERSON-NAME DATE 5 EXAMPLE OF FUNCTIONAL DEPENDENCIES Consider the following relation schema: OIL-TANKERS (HULL#, NAME, CAPTAIN-NAME, COUNTRY-BANNING) primary key: HULL#, COUNTRY-BANNING example FDs: HULL# NAME CAPTAIN-NAME o HULL# NAME OIL-TANKERS o HULL# CAPTAIN-NAME (full functional dependency) o HULL#, NAME CAPTAIN-NAME (partial functional dependency) Date- Licensed Date- Inspected COUNTRY- BANNING FD counterexample: HULL# X COUNTRY-BANNING HULL# CAPTAIN-NAME NAME ** Dependencies are defined by the database designer, based on the knowledge of the application environment (i.e. they are data-dependent) 6

1 st NORMAL FORM (1NF) NORMALIZATION IN RELATIONAL DB SYSTEMS Functional dependencies and keys may be used to develop normalization In order to avoid certain types of anomalies Normalization steps 1. FIRST NORMAL FORM No multi-valued attributes (repeating groups) ** Remove multi-valued attributes All attributes contain atomic values only Example in thedatabase of ships environment: OIL-TANKERS ( HULL#, NAME, CAPTAIN-NAME, COUNTRIES-BANNING* ) Modify it to: Or OIL-TANKERS (HULL#, NAME, CAPTAIN-NAME, COUNTRY-BANNING) OIL-TANKERS (HULL#, NAME, CAPTAIN-NAME) BANS (HULL#, COUNTRY-BANNING) 7 2 nd NORMAL FORM (2NF) 2. SECOND NORMAL FORM if 1NF and every attribute not part of the primary key is fully functionally dependent on the primary key. ** Remove partial functional dependencies 1- Example: INSPECTIONS (DATE, HULL#, RESULT, HOME-PORT) 2- Functional dependencies: DATE, HULL# RESULT HULL# HOME-PORT DATE, HULL# HOME-PORT 3- the primary key is DATE, HULL#, but HOME-PORT is partially functionally dependent on the key DATE, HULL# 4- HULL# RESULT DATE X HOME-PORT - Causes anomalies: 1 2 3 DATE HULL# RESULT HOME-PORT d1 h1 Pass L.A. d2 h1 Fail L.A. d3 h1 Pass L.A. 8

2 nd NORMAL FORM (continued) 2. SECOND NORMAL FORM (continued) 5 anomalies: Update: change HOME-PORT from L.A. to S.F. in the 1 st tuple, still key is valid, but the information is wrong since h1 has both L.A. and S.F. as home-port. Insert: h2 with home-port S.D. cannot be added until it is inspected. if we add a tuple (d4, h1, pass, S.F.), the system will not catch the inconsistency for the homeport of h1. Delete: delete the last inspection record for h1 and you also loose the information on its home-port 6 decompose to: INSEPECTION (DATE, HULL#, RESULT) SHIP-HOME-PORTS (HULL#, HOME-PORT) 9 3 rd NORMAL FORM (3NF) 3. THIRD NORMAL FORM If 2NF and every non-key attribute is non-transitively dependent on the primary key ** Remove transitive dependencies Example: 1- CREW (ID#, HULL#, HOME-PORT) 2- ID# HULL# ID# HOME-PORT HULL# HOME-PORT 3- ID# HULL# X HOME-PORT 4- But HULL# is not a candidate key in the CREW relation CREW ID# HULL# HOME-PORT h1 L.A. C2 h1 L.A. C3 h2 S.F. C4 h2 S.F. 10

3 rd NORMAL FORM (continued) 3. THIRD NORMAL FORM (continued) 5- Anomalies Update: If starts to work for h2 (HULL#) and you change h1 to h2 then it is inconsistent since h2 is in S.F. but you have it in L.A. Insert: h3 with S.D. cannot be added if there is no ID# for CREW If I add (c4 h2 S.D.), it will not be caught by the system as inconsistency for the city home-port of h2 Delete: Delete the last tuple for a crew working on a ship, and you also loose the information on the home-port of that ship 6- decompose to CREW (ID#, HULL#) SHIP-HOME-PORTS (HULL#, HOME-PORT) X CREW-HOME-PORTS (ID#, HOME-PORT) is semantically wrong and has no meaning in real life 11 4 th NORMAL FORM (4NF) 4. FOURTH NORMAL FORM Even if a relation is in third normal form, there may still remain some anomalies (problems) o Multi-valued dependency: more general than a functional dependency o A B (A multi-determines B) if B has a welldefined value (but not necessarily a single value) ** Remove multi-valued dependencies 12

4 th NORMAL FORM (continued-1) 4. FOURTH NORMAL FORM (continued) Example: CAPITAIN-NAME LICENSING-COUNTRY CAPTAIN-NAME CREW-ID# LICENSING- COUNTRY WHITE WHITE C2 C2 C3 C3 C4 C5 USA GERMANY USA GERMANY USA GERMANY ENGLAND ITALY X Wrong * This shows that captain has crew, C2, C3, and is licensed from both USA and GERMANY QUERY: Find the licensing countries for the captain of the crew c2? 13 4 th NORMAL FORM (continued-2) 4. FOURTH NORMAL FORM (continued) Example decomposed relations: CAPTAIN-CREW (CAPTAIN-NAME, CREW-ID#) CAPTAIN-LICENSES (CAPTAIN-NAME, LICENSING-COUNTRY) If all relations are in fourth normal form then, each tuple in each relation consists of one main key, plus some mutually independent attribute values * then, the key identifies an object, and other attribute values describe that object 14

5 th NORMAL FORM 5. FIFTH NORMAL FORM Even if a relation is in fourth normal form, there may still be more anomalies o Non-loss- decomposition: no loss of information (semantics) must occur with a join after a decomposition o usually, a join after a decomposition returns the original (predecomposition) relation o BUT, there may be join dependencies ** Remove join dependencies 15 RA RB RC A1 B1 C2 A2 B1 Lossy decomposition A1 B2 A1 B1 RA A1 RB B1 RB B1 RC C2 RA A1 RC C2 A2 B1 B1 A2 A1 B2 B2 A1 Join on RB X Wrong RA RB RC A1 B1 C2 A1 B1 A2 B1 C2 A2 B1 A1 B2 Join on RA+RC RA RB RC A1 B1 C2 A2 B1 A1 B1 A1 B2 16

NORMALIZATION cont. 5. FIFTH NORMAL FORM (continued) Lossless Decomposition Let R be a relation schema Let R1 and R2 form a decomposition of R This decomposition is a lossless (join) decomposition of R, if at least one of the following functional dependencies holds: o R1 R2 R1 o R1 R2 R2 U U U Thus R1 R1must form a superkeyof either R1 or R2 In the previous example: R = (RA, RB, RC) R1 = (RA, RB) R2 = (RB, RC) R1 U R2 = RB But, RBis not a superkeyof either R1 or R2, thus this decomposition is lossy 17 BENEFITS OF NORMALIZATION - WHY NORMALIZE? Avoid anomalies Reduce data redundancy (by decompositions) Capture some application environment semantics o Key represents the object-id o Other attributes describe the object Functional dependencies capture some facts about the application environment Normalization allows us to enforce those semantics into the system however, there are many other types of semantic constraints that cannot be captured by functional dependencies relational integrity constraints are required e.g. No employee s salary can be more than his manager s salary 18