Top Banner
Chapter Eight: Database Redesign Database Processing: Fundamentals, Design, and Implementation
15

Chapter Eight: Database Redesign Database Processing: Fundamentals, Design, and Implementation.

Dec 14, 2015

Download

Documents

Deborah Allport
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chapter Eight: Database Redesign Database Processing: Fundamentals, Design, and Implementation.

Chapter Eight:

Database Redesign

Database Processing:Fundamentals, Design, and Implementation

Page 2: Chapter Eight: Database Redesign Database Processing: Fundamentals, Design, and Implementation.

Non-Correlated Subquery8-2

SELECT A.Name FROM ARTIST A WHERE A.Artist IN

(SELECT W.ArtistID FROM WORK W WHERE W.Title = ‘Mystic

Fabric’);

Page 3: Chapter Eight: Database Redesign Database Processing: Fundamentals, Design, and Implementation.

Correlated Subquery8-3

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);

Page 4: Chapter Eight: Database Redesign Database Processing: Fundamentals, Design, and Implementation.

Checking Functional Dependencies

8-4

Department BudgetCode

SELECT E1.Department, E1.BudgetCode FROM EMPLOYEE E1 WHERE E1.Department IN

(SELECT E2.DepartmentFROM EMPLOYEE E2WHERE E1.Department = E2.DepartmentAND E1.BudgetCode <> E2.BudgetCode);

Page 5: Chapter Eight: Database Redesign Database Processing: Fundamentals, Design, and Implementation.

Checking Functional Dependencies

8-5

SELECT E1.Department, E1.BudgetCode FROM EMPLOYEE E1 WHERE EXISTS

(SELECT *FROM EMPLOYEE E2WHERE E1.Department = E2.Department AND E1.BudgetCode <> E2.BudgetCode);

Page 6: Chapter Eight: Database Redesign Database Processing: Fundamentals, Design, and Implementation.

Double NOT EXISTS8-6

The following code determines the name of any ARTIST that is of interest to every CUSTOMER:

SELECT A.NameFROM ARTIST AS AWHERE 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));

Page 7: Chapter Eight: Database Redesign Database Processing: Fundamentals, Design, and Implementation.

Reverse Engineered Data Model: Logical Model

8-7

Page 8: Chapter Eight: Database Redesign Database Processing: Fundamentals, Design, and Implementation.

Reverse Engineered Data Model: Physical Model

8-8

Page 9: Chapter Eight: Database Redesign Database Processing: Fundamentals, Design, and Implementation.

RE Dependency Graph: CUSTOMER with Two Views

8-9

Page 10: Chapter Eight: Database Redesign Database Processing: Fundamentals, Design, and Implementation.

RE Dependency Graph: Tables and Views [Incomplete]8-10

Page 11: Chapter Eight: Database Redesign Database Processing: Fundamentals, Design, and Implementation.

Composite Dependency Graph [Incomplete]

8-11

Page 12: Chapter Eight: Database Redesign Database Processing: Fundamentals, Design, and Implementation.

Database Redesign Changes8-12

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

Page 13: Chapter Eight: Database Redesign Database Processing: Fundamentals, Design, and Implementation.

Changing Minimum Cardinalities8-13

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

Page 14: Chapter Eight: Database Redesign Database Processing: Fundamentals, Design, and Implementation.

Changing Maximum Cardinalities: 1:N to N:M Example

8-14

Page 15: Chapter Eight: Database Redesign Database Processing: Fundamentals, Design, and Implementation.

Forward Engineering8-15

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