Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/1 Copyright © 2004 Please……. No Food Or Drink in the class.

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Advertisements

Chapter Eight: Database Redesign Database Processing: Fundamentals, Design, and Implementation.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-1 David M. Kroenke’s Chapter Eight: Database Redesign Database Processing:
Fundamentals, Design, and Implementation, 9/e Chapter 8 Database Redesign.
Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 1/1 Copyright © 2004 Please……. No Food Or Drink in the class.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 5/1 Copyright © 2004 Please……. No Food Or Drink in the class.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeAppendix A/1 Copyright © 2004 Please……. No Food Or Drink in the class.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Introduction to Structured Query Language (SQL)
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-1 David M. Kroenke’s Chapter Eight: Database Redesign Database Processing:
Fundamentals, Design, and Implementation, 9/e COS 346 Day 8.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-1 David M. Kroenke Database Processing Chapter 7/8 Structured Query.
Introduction to Structured Query Language (SQL)
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 COS 346 Day 11.
Fundamentals, Design, and Implementation, 9/e Chapter 5 Database Design.
Fundamentals, Design, and Implementation, 9/e Chapter 3 Entity-Relationship Data Modeling: Process and Examples Instructor: Dragomir R. Radev Fall 2005.
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
Prentice Hall © COS 346 Day Agenda Questions? Assignment 7 Corrected –4 A’s and 4 B’s Assignment 8 posted –Due April 6 Quiz 2 next class.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 6-1 COS 346 Day 10.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 6-1 COS 346 Day 8.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 COS 346 Day 12.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 6-1 COS 346 Day 7.
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-1 COS 346 Day 17.
Fundamentals, Design, and Implementation, 9/e Chapter 7 Using SQL in Applications.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 COS 346 Day 11.
Database Systems More SQL Database Design -- More SQL1.
Introduction to Structured Query Language (SQL)
David M. Kroenke and David J
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 6-1 David M. Kroenke’s Chapter Six: Transforming ER Models into Database.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 David M. Kroenke’s Chapter Seven: SQL for Database Construction and.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 6-1 David M. Kroenke’s Chapter Six: Transforming ER Models into Database.
Transforming Data Models into Database Designs
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
Oracle Data Definition Language (DDL)
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
Chapter Six Professor Adams’ Slides. Note that entities are shadowed, tables are not. Note that entities have no physical existence (blueprint) Note.
Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 2/1 Copyright © 2004 Please……. No Food Or Drink in the class.
Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 3/1 Copyright © 2004 Please……. No Food Or Drink in the class.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Chapter 9 Constraints. Chapter Objectives  Explain the purpose of constraints in a table  Distinguish among PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK,
Oracle 11g: SQL Chapter 4 Constraints.
SQL for Database Construction and Application Processing
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Fundamentals, Design, and Implementation, 9/e Chapter 8 Database Redesign.
1 DBS201: More on SQL Lecture 3. 2 Agenda How to use SQL to update table definitions How to update data in a table How to join tables together.
Database Processing: Fundamentals, Design and Implementation, 9/e by David M. KroenkeChapter 4/1 Copyright © 2004 Please……. No Food Or Drink in the class.
David M. Kroenke and David J. Auer Database Processing: F undamentals, Design, and Implementation Chapter Seven: SQL for Database Construction and Application.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 6-1 David M. Kroenke’s Chapter Six: Transforming Data Models into Database.
David M. Kroenke and David J. Auer Database Processing Fundamentals, Design, and Implementation Chapter Eight: Database Redesign.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
Chapter Seven: SQL for Database Construction and Application Processing.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Chapter 5 Database Design
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
David M. Kroenke and David J
COS 346 Day 8.
Database Processing: David M. Kroenke’s Chapter Six:
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Database Processing: David M. Kroenke’s Chapter Seven:
Database Processing: David M. Kroenke’s Chapter Seven:
Chapter 8 Database Redesign
Database Processing: David M. Kroenke’s Chapter Six:
Database Processing: David M. Kroenke’s Chapter Six:
Presentation transcript:

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/1 Copyright © 2004 Please……. No Food Or Drink in the class room Cell phones off Pagers on vibrate Phasers on stun

Fundamentals, Design, and Implementation, 9/e Chapter 8 Database Redesign

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/3 Copyright © 2004  To understand the need for database redesign  To be able to use correlated subqueries  To be able to use the SQL EXISTS and NOT EXISTS keywords in correlated subqueries  To understand reverse engineering  To be able to use dependency graphs OBJECTIVES

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/4 Copyright © 2004  To be able to change table names  To be able to change table columns  To be able to change relationship cardinalities  To be able to change relationship properties  To be able to add and delete relationships  To understand the need to denormalize some databases OBJECTIVES (Continued)

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/5 Copyright © 2004 Need For Database Redesign  Database redesign is necessary –To fix mistakes made during the initial database design –To adapt the database to changes in system requirements  New information systems cause changes in systems requirements because information systems and organizations create each other –When a new system is installed, users can behave in new ways –As the users behave in the new ways, they will want changes to the system to accommodate their new behaviors

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/6 Copyright © 2004 Correlated Subqueries  A correlated subquery looks similar to a regular subquery  A regular subquery can be processed from the bottom up  For a correlated subquery, the processing is nested, i.e., a row from an upper query statement is used in comparison with rows in a lower-level query

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/7 Copyright © 2004 Example: Correlated Subqueries SELECT A.Name FROM ARTIST A WHERE A.ArtistID IN (SELECT W.ArtistID FROM WORK W WHERE W.Title =’Mystic Fabric’); SELECT W1.Title, W1.Copy FROM WORK W1 WHERE W1.Title IN (SELECT W2.Title FROM WORK W2 WHERE W1.Title = W2.Title AND W1.WorkID <> W2.WorkID);

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/8 Copyright © 2004 EXISTS and NOT EXISTS  EXISTS and NOT EXISTS are specialized forms of correlated subqueries –An EXISTS condition is true if any row in the subquery meets the specified conditions –A NOT EXISTS condition is true only if all rows in the subquery do not meet the specified condition  Double use of NOT EXISTS can be used to find rows that have some specified condition to every row of a table

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/9 Copyright © 2004 Example: EXISTS SELECT E1.Department, E1.BudgetCode FROM EMPLOYEE E1 WHERE EXISTS (SELECT * FROM EMPLOYEE E2 WHERE E1.Department = E2.Department AND E1.BudgetCode <> E2.BudgetCode);

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/10 Copyright © 2004 Example: Double NOT EXISTS SELECT A.Name FROM ARTIST AS A WHERE NOT EXISTS (SELECT C.CustomerID FROM CUSTOMER C WHERE NOT EXISTS (SELECT CI.CustomerID FROM CUSTOMER_artist_int CI WHERE C.CustomerID= CI.CustomerID AND A.ArtistID = CI.ArtistID));

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/11 Copyright © 2004 Database Redesign  Three principles for database redesign: –Measure twice and cut once: understand the current structure and contents of the database before making any structure changes –Test the new changes on a test database before making real changes –Create a complete backup of the operational database before making any structure changes  Technique: reverse engineering (RE)

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/12 Copyright © 2004 Reverse Engineering  Reverse engineering is the process of reading and producing a data model from a database schema  A reverse engineered (RE) data model –Provides a basis to begin the database redesign project –Is neither truly a conceptual nor an internal schema as it has characteristics of both –Should be carefully reviewed because it almost always has missing information

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/13 Copyright © 2004 Example: RE Data Model

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/14 Copyright © 2004 Dependency Graphs  Dependency graphs are diagrams used to portray the dependency of one element on another

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/15 Copyright © 2004 Example: Dependency Graph

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/16 Copyright © 2004 Database Backup and Test Databases  Before making any changes to an operational database –A complete backup of the operational database should be made –Any proposed changes should be thoroughly tested  Three different copies of the database schema used in the redesign process –A small test database for initial testing –A large test database for secondary testing –The operational database

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/17 Copyright © 2004 Database Redesign Changes  Changing tables and columns –Changing table names –Adding and dropping table columns –Changing data type or constraints –Adding and dropping constraints  Changing relationships –Changing cardinalities –Adding and deleting relationships –Adding and removing relationship for de- normalization

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/18 Copyright © 2004 Changing Table Names  There is no SQL-92 command to change table name –The table needs to be re-created under the new name, tested, and the old table is dropped  Changing a table name has a surprising number of potential consequences –Therefore, using views defined as table aliases is more appropriate –Only views that define the aliases would need to be changed when the source table name is changed

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/19 Copyright © 2004 Adding Columns  To add null columns to a table –ALTER TABLE WORK ADD COLUMN DateCreated Date NULL;  Other column constraints, e.g., DEFAULT or UNIQUE, may be included with the column definition  Newly added DEFAULT constraint will be applied to only new rows, existing rows will have null values  Three steps to add a NOT NULL column: –Add the column as NULL –Add data to every row –Alter the column constraint to NOT NULL

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/20 Copyright © 2004 Dropping Columns  To drop non-key columns –ALTER TABLE WORK DROP COLUMN DateCreated;  To drop a foreign key column, the foreign key constraint must first be dropped  To drop the primary key, all foreign keys using the primary key must first be dropped; follow by dropping the primary key constraint

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/21 Copyright © 2004 Changing Data Type or Constraints  Use the ALTER TABLE ALTER COLUMN to change data types and constraints  For some changes, data will be lost or the DBMS may refuse the change  To change a constraint from NULL to NOT NULL, all rows must have a value first

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/22 Copyright © 2004 Changing Data Type or Constraints  Converting more specific data type, e.g., date, money, and numeric, to char or varchar will usually succeed –Changing a data type from char or varchar to a more specific type can be a problem  Example ALTER TABLE ARTIST ALTER COLUMN Birthdate Numeric (4,0) NULL;

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/23 Copyright © 2004 Adding and Dropping Constraints  Use the ALTER TABLE ADD (DROP) CONSTRAINT to add (remove) constraints  Example ALTER TABLE ARTIST ADD CONSTRAINT NumericBirthYearCheck CHECK (Birthdate > 1900 and Birthdate < 2100);

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/24 Copyright © 2004 Changing Minimum Cardinalities  On the parent side: –To change from zero to one, change the foreign key constraint from NULL to NOT NULL Can only be done if all the rows in the table have a value –To change from one to zero, change the foreign key constraint from NOT NULL to NULL  On the child side: –Add (to change from zero to one) or drop (to change from one to zero) triggers that enforce the constraint

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/25 Copyright © 2004 Changing Maximum Cardinalities  Changing from 1:1 to 1:N –If the foreign key is in the correct table, remove the unique constraint on the foreign key column –If the foreign key is in the wrong table, move the foreign key to the correct table and do not place a unique constraint on that table  Changing from 1:N to N:M –Build a new intersection table and move the key and foreign key values to the intersection table

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/26 Copyright © 2004 Reducing Cardinalities  Reducing cardinalities may result in data loss  Reducing N:M to 1:N –Create a foreign key in the parent table and move one value from the intersection table into that foreign key  Reducing 1:N to 1:1 –Remove any duplicates in the foreign key and then set a uniqueness constraint on that key

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/27 Copyright © 2004 Adding and Deleting Relationships  Adding new tables and relationships –Add the tables and relationships using CREATE TABLE statements with FOREIGN KEY constraints –If an existing table has a child relationship to the new table, add a FOREIGN KEY constraint using the existing table  Deleting relationships and tables –Drop the foreign key constraints and then drop the tables

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/28 Copyright © 2004 Adding Tables and Relationships for Normalization  Steps: –Use correlated subqueries to determine whether the normalization assumption is justified If not, fix the data before proceeding –Create a new table and move the normalized data into the new table –Define the appropriate foreign key

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/29 Copyright © 2004 Removing Relationships for Denormalization  Steps: –Define the new columns in the table to be denormalized –Fill the table with existing data –Drop the child table and relationship

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/30 Copyright © 2004 Forward Engineering  Forward engineering is the process of applying data model changes to an existing database  Results of forward engineering should be tested before using it on an operational database  Some tools will show the SQL that will execute during the forward engineering process –If so, that SQL should be carefully reviewed

Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/31 Copyright © 2004 Reminder DO NOT FORGET TO SIGN THE ATTENDANCE SHEET BEFORE YOU LEAVE TONIGHT