DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-1 David M. Kroenke’s Chapter Eight: Database Redesign Database Processing:

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 5/1 Copyright © 2004 Please……. No Food Or Drink in the class.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 5-1 COS 346 Day 6.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 8.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 5-1 COS 346 Day 9.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 4-1 David M. Kroenke Database Processing Chapter 7/8 Structured Query.
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.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 6-1 David M. Kroenke Database Processing Chapter 6 Transforming Data.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 5-1 David M. Kroenke Database Processing Tenth Edition Chapter 5 Data.
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.
© 2008 Pearson Prentice Hall, Experiencing MIS, David Kroenke
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.
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.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 6 Database Design Using Entity- Relationship Models.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 7-1 COS 346 Day 11.
Structured Query Language Chapter Three (Excerpts) DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Introduction to Structured Query Language (SQL)
Structured Query Language Chapter Three DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
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 4-1 David M. Kroenke Database Processing Chapter 7 Structured Query Language.
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.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 5-1 David M. Kroenke’s Chapter Five: Data Modeling with the Entity-Relationship.
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 11-1 David M. Kroenke’s Chapter Eleven: Managing Databases with SQL Server.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
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.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL for Database Construction and Application Processing
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 8/1 Copyright © 2004 Please……. No Food Or Drink in the class.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
Fundamentals, Design, and Implementation, 9/e Chapter 8 Database Redesign.
David M. Kroenke and David J. Auer Database Processing: F undamentals, Design, and Implementation Chapter Seven: SQL for Database Construction and Application.
Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall Chapter 9 Designing Databases 9.1.
© 2002 by Prentice Hall 1 Structured Query Language David M. Kroenke Database Concepts 1e Chapter 3 3.
David M. Kroenke and David J. Auer Database Processing Fundamentals, Design, and Implementation Chapter Seven: SQL for Database Construction and Application.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 5 (Part a): Logical Database Design and the Relational Model Modern Database Management.
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’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 5-1 David M. Kroenke’s Chapter Five: Data Modeling with the Entity-Relationship.
David M. Kroenke and David J. Auer Database Processing Fundamentals, Design, and Implementation Chapter Eight: Database Redesign.
Chapter Seven: SQL for Database Construction and Application Processing.
Chapter 5 Database Design
Chapter 4: Logical Database Design and the Relational Model
David M. Kroenke and David J
COS 346 Day 8.
Database Processing: David M. Kroenke’s Chapter Six:
Database Processing: David M. Kroenke’s Chapter Seven:
Database Processing: David M. Kroenke’s Chapter Six:
Database Processing: David M. Kroenke’s Chapter Seven:
Database Processing: David M. Kroenke’s Chapter Five:
Database Processing: David M. Kroenke’s Chapter Five:
Chapter 8 Database Redesign
Database Processing: David M. Kroenke’s Chapter Six:
Database Processing: David M. Kroenke’s Chapter Six:
© 2008 Pearson Prentice Hall, Experiencing MIS, David Kroenke
Presentation transcript:

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

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-2 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 may want to change the system to accommodate their new behaviors

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-3 Correlated Subqueries A correlated subquery looks similar to a regular subquery –But, a regular subquery can be processed from the bottom up With a correlated subquery… –each row from the upper-level query statement is compared with rows in the lower-level query

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-4 Refresher: Regular (non-correlated) Subquery It contains two different tables (or combinations of tables) in the two levels of the query: –ARTIST in the top level query –WORK in the inner, lower level subquery SELECTName FROMARTIST WHEREArtist IN (SELECTArtistID FROMWORK WHERE Title = ‘Mystic Fabric‘); Done first

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-5 Correlated Subquery This subquery contains the same table in both levels SELECT W1.Title, W1.Copy FROMWORK W1 WHERE W1.Title IN (SELECT W2.Title FROM WORK W2 WHERE W1.Title = W2.Title AND W1.WorkID <> W2.WorkID); What does this query do?

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-6 Checking Functional Dependencies In general, we can use correlated subqueries to check for any rows that violate a given functional dependency. Example: Check for Department  BudgetCode SELECT E1.Department, E1.BudgetCode FROM EMPLOYEE E1 WHERE E1.Department IN (SELECT E2.Department FROM EMPLOYEE E2 WHERE E1.Department = E2.Department AND E1.BudgetCode <> E2.BudgetCode);

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-7 EXISTS and NOT EXISTS 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 –The use of a double NOT EXISTS can be used to find rows that have some specified condition to every row of a table

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-8 EXISTS to Check Functional Dependencies Finding violators of the previous functional dependency ( Department  BudgetCode) using EXISTS - looking for any row: SELECT E1.Department, E1.BudgetCode FROM EMPLOYEE E1 WHERE EXISTS (SELECT * FROM EMPLOYEE E2 WHERE E1.Department = E2.Department AND E1.BudgetCode <> E2.BudgetCode);

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-9 Double NOT EXISTS This determines the name of any ARTIST that is of interest to every CUSTOMER: 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));

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-10 Database Redesign Three principles for database redesign: –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 Reverse Engineering (RE) technique

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-11 Reverse Engineering (RE) Reverse engineering is the process of reading and producing a data model from a database schema A reverse engineered 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

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-12 Reverse Engineered Data Model: Logical Model

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-13 Reverse Engineered Data Model: Physical Model

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-14 Dependency Graphs Dependency graphs are diagrams used to portray the dependency of one element on another A B Entity A is referenced by Entity B

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-15 RE Dependency Graph: Tables and Views [partial]

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-16 Composite Dependency Graph [partial]

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-17 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

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-18 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

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-19 Changing Table Names To change table name: –The table needs to be re-created under the new name, tested, and then the old table is dropped Changing a table name has a surprising number of potential consequences: –Relying on views to access all tables makes this a bit easier to deal with –Only views that define the aliases would need to be changed when the source table name is changed

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-20 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

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-21 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

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-22 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

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-23 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;

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-24 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);

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-25 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

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-26 Changing Maximum Cardinalities: 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

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-27 Changing Maximum Cardinalities: 1:1 to 1:N Example

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-28 Changing Maximum Cardinalities: 1:N to N:M Build a new intersection table and move the key and foreign key values to the intersection table

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-29 Changing Maximum Cardinalities: 1:N to N:M Example

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-30 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

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-31 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