RELATIONAL DATABASE DESIGN Good Database Design Principles



Similar documents
Normalization NORMALIZATION. Primary keys (contd.) Primary keys

Normalization of Database

DATABASE SYSTEMS. Chapter 7 Normalisation

RELATIONAL DATABASE DESIGN. Basic Concepts

Chapter 15 Basics of Functional Dependencies and Normalization for Relational Databases

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

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

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

Chapter 9: Normalization

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

Chapter 6. Database Tables & Normalization. The Need for Normalization. Database Tables & Normalization

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

Part 6. Normalization

Normalisation to 3NF. Database Systems Lecture 11 Natasha Alechina

DATABASE NORMALIZATION

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

RELATIONAL DATABASE DESIGN

DBMS. Normalization. Module Title?

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

Database Management System

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

Normalisation 6 TABLE OF CONTENTS LEARNING OUTCOMES

MCQs~Databases~Relational Model and Normalization

Lecture 2 Normalization

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.

Database Concepts II. Top down V Bottom up database design. database design (Cont) 3/22/2010. Chapter 4

Tutorial on Relational Database Design

Functional Dependency and Normalization for Relational Databases

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

Topic 5.1: Database Tables and Normalization

Module 5: Normalization of database tables

Normalization in OODB Design

Normalization. Normalization. Normalization. Data Redundancy

Normalization in Database Design

SAMPLE FINAL EXAMINATION SPRING SESSION 2015

Normalization. CIS 331: Introduction to Database Systems

The 3 Normal Forms: Copyright Fred Coulson 2007 (last revised February 1, 2009)

Fundamentals of Database System

Normal forms and normalization

Database Design and Normalization

14 Databases. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to:

DATABASE DESIGN: Normalization Exercises & Answers

1.204 Lecture 2. Keys

Introduction to normalization. Introduction to normalization

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

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

Introduction to Relational Database. David Gerbing. School of Business Administration. Portland State University

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

Teaching Database Modeling and Design: Areas of Confusion and Helpful Hints

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

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

Database Design and the Reality of Normalisation

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

DATABASE MANAGEMENT SYSTEMS. Question Bank:

Database Management Systems. Redundancy and Other Problems. Redundancy

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

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

Determination of the normalization level of database schemas through equivalence classes of attributes

Designing Databases. Introduction

Fundamentals of Relational Database Design

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

Unit 2786 (V7) Create and use a computer database to solve a problem. with. Microsoft Access Easy to follow

Normalisation 1. Chapter 4.1 V4.0. Napier University

Introduction to Microsoft Access

Chapter 7: Relational Database Design

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

Chapter 1: Introduction

Functional Dependencies and Finding a Minimal Cover

LOGICAL DATABASE DESIGN

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

BCA. Database Management System

Database Design Basics

Objectives, outcomes, and key concepts. Objectives: give an overview of the normal forms and their benefits and problems.

CS143 Notes: Normalization Theory

Design of Relational Database Schemas

KNOWLEDGE FACTORING USING NORMALIZATION THEORY

Physical Database Design and Tuning

Faculty of Engineering and Architecture. Computer Engineering Department DATABASE MANAGEMENT SYSTEMS POSTLAB #3 SOLUTION

1. Physical Database Design in Relational Databases (1)

Conceptual Design: Entity Relationship Models. Objectives. Overview

UNDERSTANDING NORMALIZATION

Chapter 8. Database Design II: Relational Normalization Theory

Analysis and Design Complex and Large Data Base using MySQL Workbench

Theory of Relational Database Design and Normalization

Normalization. Reduces the liklihood of anomolies

Schema Refinement, Functional Dependencies, Normalization

Chapter 1: Introduction. Database Management System (DBMS)

Normalization of database model. Pazmany Peter Catholic University 2005 Zoltan Fodroczi

Introduction to database management systems

Database Fundamentals: 1

Normalizing SAS Datasets Using User Define Formats

OBJECT ORIENTED EXTENSIONS TO SQL

Chapter 10 Functional Dependencies and Normalization for Relational Databases

Boyce-Codd Normal Form

Chapter 5: FUNCTIONAL DEPENDENCIES AND NORMALIZATION FOR RELATIONAL DATABASES

How To Write A Diagram

Transcription:

Good Database Design Principles 1. no redundancy a field is stored in only one table, unless it happens to be a foreign key replication of foreign keys is permissible, because they allow two tables to be joined together 2. no bad dependencies in the dependency diagram of any relation in the database, the determinant should be the whole primary key, or a candidate key. Violations of this rule include: partial dependencies transitive dependencies normalization is the process of eliminating bad dependencies by splitting up tables and linking them with foreign keys normal forms are categories that classify how completely a table has been normalized there are six recognized normal forms (NF): First Normal Form (1NF) Second Normal Form (2NF) Third Normal Form (3NF) Boyce-Codd Normal Form (BCNF) Fourth Normal Form (4NF) Fifth Normal Form (5NF) Relational Database Design 13

First Normal Form a table is said to be in the first normal form (1NF) if all its attributes are atomic. Attributes that are not atomic go by the names Nested relations, nested tables, or sub-tables Repeating groups or repeating sections List-valued attributes example of a table that is not in first normal form: Client Client VetID Vet PetID Pet PetType ID 2173 Barbara Hennessey 27 PetVet 1 2 3 Sam Hoober Tom Bird Dog Hamster 4519 Vernon Noordsy 31 PetCare 2 Charlie Cat 8005 Sandra Amidon 27 PetVet 1 2 Beefer Kirby Dog Cat 8112 Helen Wandzell 24 PetsRUs 3 Kirby Dog CLIENT(ClientD, Client, VetID, Vet, PET(PetID, Pet, PetType) ) This kind of nested or hierarchical form is a very natural way for people to think about or view data. However, the relational database philosophy claims that it may not be a very good way for computers to store some kinds of data. Over the years, a lot of information systems have stored data in this kind of format but they were not relational databases Relational Database Design 14

In order to eliminate the nested relation, pull out the nested relation and form a new table Be sure to include the old key in the new table so that you can connect the tables back together. Client ClientID VetID Vet CLIENT ClientID Pet PET PetID Pet Type CLIENT(ClientD, Client, VetID, Vet) PET(ClientID, PetID, Pet, PetType) ClientID foreign key to CLIENT In this particular example, note that PetID is only unique within sets of pets with the same owner. Relational Database Design 15

Second Normal Form Recall: a partial dependency occurs when You have a composite primary key A non-key attribute depends on part of the primary key, but not all of it A table in 1NF is said to be in the second normal form (2NF) if it does not contain any partial dependencies. Example of a partial dependency: ACTIVITY(StudentID, Activity, Fee) on pages 6, 7, and 9 StudentID Fee Activity Our new CLIENT-PET database does not have any partial dependencies So, it already in second normal form But it still has a transitive dependency : Client ClientID VetID Vet Relational Database Design 16

Third Normal Form Recall: a transitive dependency happens when a non-key attribute depends on another non-key attribute, and that attribute could not have been used as an alternative primary key (or the same thing for a composition of several attributes). A table of 2NF is said to be in the third normal form (3NF) if it does not contain any transitive dependencies, In order to eliminate transitive dependency, we split the CLIENTS table again: CLIENTS(ClientID, Client, VetID) VetID foreign key to VET PETS(ClientID, PetID, Pet, PetType) ClientID foreign key to CLIENT VETS(VetID, Vet) CLIENT Client ClientID VetID VET VetID Vet PET ClientID Pet PetID Pet Type Relational Database Design 17

Third Normal Form (Cont.) CLIENTS-PETS-VETS database in third normal form: Client ID Client VetID 2173 Barbara Hennessey 27 4519 Vernon Noordsy 31 8005 Sandra Amidon 27 8112 Helen Wandzell 24 VetID Vet 27 PetVet 31 PetCare 24 PetsRUs Client PetID Pet PetType ID 2173 1 Sam Bird 2173 2 Hoober Dog 2173 3 Tom Hamster 4519 2 Charlie Cat 8005 1 Beefer Dog 8005 2 Kirby Cat 8112 3 Kirby Dog with MS Access table relationships the database consists of three types of entities, stored as distinct relations in separate tables: clients (CLIENTS) pets ( PETS) vets (VETS) there is no redundancy (only foreign keys are replicated) there are no partial and transitive dependencies Relational Database Design 18

Normal Forms and Normalization The distinctions between third normal form (3NF), Boyce- Codd normal form (BCNF), fourth normal form (4NF), and fifth normal form (5NF) are subtle. They have to do with overlapping sets of attributes that could be used as primary keys (composite candidate keys). For our purposes, it s enough to know about 3NF. You need to be able to put a database in 3NF. That is more important than recognizing 1NF and 2NF Key factors to recognize 3NF: All attributes atomic gives you 1NF. Every determinant in every relationship is the whole primary key (or could have been chosen as an alternative primary key) guarantees no partial or transitive dependencies. Redesigning a database so it s in 3NF is called normalization. Relational Database Design 19

Example With Multiple Candidate Keys DRIVER(License#, SocialSecurity#, Gender, BirthDate) Gender License# Social Security# BirthDate The dependencies SocialSecurity# Gender and SocialSecurity# BirthDate are not considered transitive because we could have chosen SocialSecurity# as the primary key for the table. This kind of design will not give rise to anomalies. Relational Database Design 20

Normalization Example: Hardware Store Database the ORDERS table : Order Cust Order Cust ProdDescr Prod Quantity Numb Code Date Price 10001 5217 11/22/94 Williams Hammer $8.99 2 10001 5217 11/22/94 Williams Screwdriver $4.45 1 10002 5021 11/22/94 Johnson Clipper $18.22 1 10002 5021 11/22/94 Johnson Screwdriver $4.45 3 10002 5021 11/22/94 Johnson Crowbar $11.07 1 10002 5021 11/22/94 Johnson Saw $14.99 1 10003 4118 11/22/94 Lorenzo Hammer $8.99 1 10004 6002 11/22/94 Kopiusko Saw $14.99 1 10004 6002 11/22/94 Kopiusko Screwdriver $4.45 2 10005 5021 11/23/94 Johnson Cordlessdrill $34.95 1 Note: in practice, we would also want to have product codes as well as descriptions, and use the product codes as keys to identify products. Here, we ll identify products by their ProdDescr to keep the number of fields down. Relational Database Design 21

Example: Hardware Store Database (Cont.) ORDERS(OrderNum, ProdDescr, CustCode, OrderDate, Cust, ProdPrice, Quantity) Conversion of the hardware store database to 2NF QUANTITY(OrderNum, ProdDescr, Quantity) OrderNum foreign key to ORDERS ProdDescr foreign key to PRODUCTS PRODUCTS(ProdDescr, ProdPrice) ORDERS(OrderNum, CustCode, OrderDate, Cust) OrderNum Quantity ProdDescr ProdPrice ProdDescr OrderNum CustCode Order Date Cust Transitive Relational Database Design 22

Example: Hardware Store Database (Cont.) conversion of the ORDERS relation to 3NF QUANTITY(OrderNum, ProdDescr, Quantity) OrderNum foreign key to ORDERS ProdDescr foreign key to PRODUCTS PRODUCTS(ProdDescr, ProdPrice) ORDERS(OrderNum, CustCode, OrderDate) CustCode foreign key to CUSTOMERS CUSTOMERS(CustCode, Cust) OrderNum Quantity ProdDescr ProdPrice ProdDescr CustCode OrderNum CustCode Cust Order Date Relational Database Design 23

Example: Video Store Database the CUSTOMER relation: Customer ID Phone Last First Address City State Zip Code 1 502-666-7777 Johnson Martha 125 Main St. Alvaton KY 42122 2 502-888-6464 Smith Jack 873 Elm St. Bowling KY 42101 Green 3 502-777-7575 Washington Elroy 95 Easy St. Smith s KY 42171 Grove 4 502-333-9494 Adams Samuel 746 Brown Dr. Alvation KY 42122 5 502-474-4746 Steinmetz Susan 15 Speedway Dr. Portland TN 37148......... the RENTALFORM relation: Trans Rent Customer Video Copy# Title Rent ID Date ID ID 1 4/18/95 3 1 2 2001:SpaceOdyssey $1.50 1 4/18/95 3 6 3 Clockwork Orange $1.50 2 4/18/95 7 8 1 Hopscotch $1.50 2 4/18/95 7 2 1 Apocalypse Now $2.00 2 4/18/95 7 6 1 Clockwork Orange $1.50 3 4/18/95 8 9 1 Luggage of the Gods $2.50....... a customer can rent multiple videos as part of the same transaction multiple copies of the same video exist the copy# field stores the number of the copy unique only with copies of that same video one customer cannot rent two copies of the same video at the same time although it has two tables, the database still contains some anomalies Relational Database Design 24

Example: Video Store Database (Cont.) relations for the video store database CUSTOMER(CustomerID, Phone,, Address, City, State, ZipCode) RENTALFORM(TransID, RentDate, CustomerID, VideoID, Copy#, Title, Rent) dependency diagram for the video store database Phone Address Customer ID City State Zip TransID RentDate Customer ID Copy# VideoID Title Rent Relational Database Design 25

Example: Video Store Database (Cont.) video store database after eliminating partial and transitive dependencies CUSTOMER(CustomerID, Phone,, Address, City, State, ZipCode) RENTAL(TransID, RentDate, CustomerID) CustomerID foreign key to CUSTOMER VIDEO(VideoID, Title, Rent) VIDEOSRENTED(TransID, VideoID, Copy#) TransID foreign key to RENTAL VideoID foreign key to VIDEO Phone Address Customer ID City State Zip TransID RentDate Copy# TransID VideoID Customer ID VideoID Title Rent Relational Database Design 26

Example: Video Store Database (Cont.) table relationships for the video store database Relational Database Design 27

Summary of Guidelines for Database Design identify the entities involved in the database identify the fields relevant for each entity and define the corresponding relations determine the primary key of each relation avoid data redundancy, but have some common fields so that tables can be joined together ensure that all the required database processing can be done using the defined relations normalize the relations by splitting them into smaller ones Relational Database Design 28