Database Design and Implementation

Slides:



Advertisements
Similar presentations
Database Design: Normalization J.G. Zheng June 29 th 2005 DB Chapter 4.
Advertisements

Normal forms - 1NF, 2NF and 3NF
FEN Introduction to the database field: Quality checking table design: Design Guidelines Normalisation Seminar: Introduction to relational.
Normalisation to 3NF Database Systems Lecture 11 Natasha Alechina.
Boyce-Codd NF Takahiko Saito Spring 2005 CS 157A.
Jump to first page Normalization Jump to first page Topics n Why normalization is needed n What causes anomalies n What the 4 normal forms are n How.
Design Guidelines Normalisation Table Design. Informal Design Guidelines Table Semantics A table should hold information about one and only one entity/concept.
Database Design Conceptual –identify important entities and relationships –determine attribute domains and candidate keys –draw the E-R diagram Logical.
Boyce-Codd Normal Form Kelvin Nishikawa SE157a-03 Fall 2006 Kelvin Nishikawa SE157a-03 Fall 2006.
Why Normalization? To Reduce Redundancy to 1.avoid modification, insertion, deletion anomolies 2.save space Goal: One Fact in One Place.
Lecture 12 Inst: Haya Sammaneh
CMPE 226 Database Systems September 16 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
Lecture 6 Normalization: Advanced forms. Objectives How inference rules can identify a set of all functional dependencies for a relation. How Inference.
Your name here. Improving Schemas and Normalization What are redundancies and anomalies? What are functional dependencies and how are they related to.
SALINI SUDESH. Primarily a tool to validate and improve a logical design so that it satisfies certain constraints that avoid unnecessary duplication of.
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.
Normal Forms through BCNF CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems by Connolly & Begg, © Addison Wesley 2002)
Databases in Web Devolvement By Andy Larson Using Microsoft Sever 2000 with ASP Database Integrity Inserting data Stored procedures Views Triggers Tips.
Module 3 Designing and Implementing Tables. Module Overview Designing Tables Working with Schemas Creating and Altering Tables.
In this session, you will learn to: Describe data redundancy Describe the first, second, and third normal forms Describe the Boyce-Codd Normal Form Appreciate.
Chapter 5.1 and 5.2 Brian Cobarrubia Database Management Systems II January 31, 2008.
Normalization ACSC 425 Database Management Systems.
Copyright © Curt Hill Schema Refinement II 2 nd NF to 3 rd NF to BCNF.
1 CS122A: Introduction to Data Management Lecture #13: Relational DB Design Theory (II) Instructor: Chen Li.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under.
INF1343, Week 6 Implementing a Database with SQL This presentation is licensed under Creative Commons Attribution License, v To view a copy of this.
CCT395, Week 11 Review, Permissions Physical Storage and Performance This presentation is licensed under Creative Commons Attribution License, v. 3.0.
CCT395, Week 6 Implementing a Database with SQL and a Case Study Exercise This presentation is licensed under Creative Commons Attribution License, v.
Database Design and Implementation
CCT395, Week 2 Introduction to SQL Yuri Takhteyev September 15, 2010
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
CCT395, Week 5 Translating ER into Relations; Normalization This presentation is licensed under Creative Commons Attribution License, v To view a.
INF1343, Winter 2011 Data Modeling and Database Design Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
Normalization.
Perancangan Basis Data
Translating ER into Relations; Normalization
Advanced Normalization
CS422 Principles of Database Systems Normalization
Special Topics in CCIT: Databases
CCT1343, Week 2 Single-Table SQL Yuri Takhteyev University of Toronto
Normalization Karolina muszyńska
CS 3630 Database Design and Implementation
A brief summary of database normalization
Chapter 5: Logical Database Design and the Relational Model
Quiz Questions Q.1 An entity set that does not have sufficient attributes to form a primary key is a (A) strong entity set. (B) weak entity set. (C) simple.
Database Design and Implementation
Data Modeling and Database Design
Data Modeling and Database Design INF1343, Winter 2012 Yuri Takhteyev
Database Design and Implementation
Data Modeling and Database Design INF1343, Winter 2012 Yuri Takhteyev
Advanced Normalization
CMPE 226 Database Systems February 21 Class Meeting
Database Normalization
Module 5: Overview of Normalization
Schema Refinement What and why
Database solutions The process of normalization Marzena Nowakowska Faculty of Management and Computer Modelling Kielce University of Technology rooms:
Normalization.
Chapter 15 Basics of Functional Dependencies and Normalization for Relational Databases.
Normalization Normalization theory is based on the observation that relations with certain properties are more effective in inserting, updating and deleting.
CS 405G: Introduction to Database Systems
Sampath Jayarathna Cal Poly Pomona
Sampath Jayarathna Cal Poly Pomona
Database Normalization.
Instructor: Samia arshad
Database Management System
Database.
Chapter 7a: Overview of Database Design -- Normalization
Functional Dependencies and Normalization
Presentation transcript:

Database Design and Implementation CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution License, v. 3.0. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/. This presentation incorporates images from the Crystal Clear icon collection by Everaldo Coelho, available under LGPL from http://everaldo.com/crystal/.

Week 6 Normalization

1. Start with something, then fix it 2. Start by modeling Two Approaches 1. Start with something, then fix it 2. Start by modeling Normalization

What Problems? problem type cause solution update redundancy decomposition insertion deletion

Normal Forms 5th Normal Form 4th Normal Form BC Normal Form fixing weird issues 4th Normal Form BC Normal Form 3rd Normal Form you can do it! 2nd Normal Form 1st Normal Form trivial!

No multi-valued attributes 1NF No multi-valued attributes

pet_id owner names 1 Bob “Slim”, “the Serpent”, “Ribbon” 2 Gwen “Fluffy”, “Big Dog”

The Wrong Solution pet_id owner name1 name2 name3 1 Bob “Slim” “the Serpent” “Ribbon” 2 Gwen “Fluffy” “Big Dog”

The Right Solution pet_id owner 1 Bob 2 Gwen pet_id names 1 Slim the Serpent Ribbon 2 Fluffy Big Dog

Getting rid of “functional dependencies” 2NF and 3NF Getting rid of “functional dependencies”

pet_id → pet_name, owner_email, owner_name owner_email → owner_name ... pet_id → pet_name, owner_email, owner_name owner_email → owner_name

Functional Dependency pet_id → owner_name “owner_name is functionally depend on pet_id” “pet_id functionally determines owner_id” “owner_name describes pet_id”

(movie_id, title, year, rating) movie → title, year, rating Examples (movie_id, title, year, rating) movie → title, year, rating

Examples (building_code, room_no, session_code, time_slot, course_code) building_code, room_no, session_code, time_slot → course_code

Examples (building_code, room_no, session_code, time_slot, course_code, course_title) building_code, room_no, session_code, time_slot → course_code, course_title course_code → course_title

Examples (building_code, room_no, session_code, time_slot, course_code, course_title, year, instructor_utorid, instructor_name)

Examples (building_code, room_no, session_code, time_slot, course_code, course_title, year, instructor_utorid, instructor_name, leap_year, instructor_employee_no, instructor_rank, num_students, room_capacity)

Full Dependency a full key → attribute (This is what we want to see.) “Each attribute must describe the key, the whole key, and nothing but the key. So help me Codd.”

Partial Dependency part of a key → non-key attribute (building_code, room_number, building_name, capacity) Keys: (building_code, room_number) A partial dependency: building_code → building_name

Examples (pet_id, pet_name, owner_name) (gadget_id, agent_id) (city_name, province_code, province_name, population)

No partial dependencies 2nd Normal Form No partial dependencies

Getting to 2NF Decomposition: (building_code, room_number, building_name, capacity) capacity) (building_code, building_name)

Transitive Dependency non-key attribute → non-key attribute (a simplified definition) (pet_id, pet_name, species_id, species_name) Keys: pet_id A transitive dependency: species_id → species_name

No transitive dependencies 3rd Normal Form No transitive dependencies

Getting to 3NF Decomposition: (pet_id, pet_name, species_id, species_name) (pet_id, pet_name, species_id) (species_id, species_name)

Examples (building_code, room_no, session_code, time_slot, course_code, course_title, year, instructor_utorid, instructor_name, leap_year, instructor_employee_no, instructor_rank, num_students, room_capacity)

Examples (building_code, room_no, session_code, time_slot, course_code, instructor, num_students) (building_code, room_no, room_capacity) (session_code, year) (year, leap_year) (course_code, course_title) (instructor_utorid, instructor_name, instructor_employee_no, instructor_rank)

Better Yet (room_id, building_code, room_no, room_capacity) (room_id, session_code, time_slot, course_code, instructor, num_students) (session_code, year) (year, leap_year) (course_code, course_title) (instructor_utorid, instructor_name, instructor_employee_no, instructor_rank)

Boyce-Codd NF “All determinants must be candidate keys.” (Closes a “loophole” in 3NF.)

BCNF (instructor_id, instructor_utorid, time_slot) Keys: (instructor_id, time_slot) (instructor_utoroid, time_slot) instructor_id → instructor_utorid instructor_utorid → instructor_id (3NF, but not BCNF)

3NF vs. BCNF It is always possible to decompose a table into 3NF, but not always into BCNF.

4NF Similar to BCNF but based on multivalued dependencies (↠). Usually implies mistaking a binary relationships for ternary. Examples tend to look contrived. Not going to be on the exam.

5NF We could break this table up and then re-create it with a join. (A simplified definition.) Again, examples tend to look contrived. Not going to be on the exam.

Questions?

alter table «table» add column «column» «type»; Alter Table: Add alter table «table» add column «column» «type»; alter table pet add column pet_id integer;

alter table «table» drop column «column»; Alter Table: Drop alter table «table» drop column «column»; alter table pet drop column pet_id;

alter table «table» modify column «column» «type»; Alter Table: Modify alter table «table» modify column «column» «type»; alter table pet modify column pet_id char(5);

alter table «old_name» rename «new_name»; Alter Table: Rename alter table «old_name» rename «new_name»; alter table pet rename animal;

Adding Constraints alter table «table» add constraint foreign key «foreign key constraint»; alter table pet add constraint foreign key (owner_id) references owner(owner_id);

Drop the table. Create a new one. Alternatively... Drop the table. Create a new one.

The Final Project Get started!

Madame Z’s Database Revisited Week 3 Exercises Madame Z’s Database Revisited