Presentation is loading. Please wait.

Presentation is loading. Please wait.

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-1 COS 346 Day 17.

Similar presentations


Presentation on theme: "DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-1 COS 346 Day 17."— Presentation transcript:

1 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-1 COS 346 Day 17

2 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-2 Agenda Questions Assignment 6 Corrected –2 A’s, 2 B’s, 3 C’s and 1 D –Many students had output that was correct but could not have been produced from the SQL code they submitted. How can this happen??? Assignment 7 posted –Chap 7,8,9 & 10 –Due April 3 Quiz 2 on Apr 3 –DP Chap 7 & 8 – SQL Chap 3-10 –M/C and Short Essay Today We will finish discussing Database redesign

3 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-3 Adding and Dropping Constraints Use the ALTER TABLE ADD (DROP) CONSTRAINT to add (remove) constraints Example ALTER TABLE ARTIST ADD (DROP) CONSTRAINT NumericBirthYearCheck CHECK (Birthdate > 1900 and Birthdate < 2100);

4 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-4 Changing cardinality Minimum Cardinality –0 -> 1 Not required to required –1 -> 0 required to not required Maximum Cardinality –1:1 -> 1:N -> N:M –N:M -> 1:N -> 1:1 Loss of data

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

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

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

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

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

10 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-10 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 Make sure all views, stored procedures, and application code are modified to account for the new relationship

11 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-11 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 Make sure all views, stored procedures, and application code are modified to account for the changes in relationships and tables

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

13 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-13 David M. Kroenke’s Database Processing Fundamentals, Design, and Implementation (10 th Edition) End of Presentation: Chapter Eight


Download ppt "DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 8-1 COS 346 Day 17."

Similar presentations


Ads by Google