Presentation is loading. Please wait.

Presentation is loading. Please wait.

Normalizing an Existing Table

Similar presentations


Presentation on theme: "Normalizing an Existing Table"— Presentation transcript:

1 Normalizing an Existing Table
MigratingData 8/28/2018 Normalizing an Existing Table Migrating Data from a Single Table to Multiple Tables Or How can I smoothly convert my 1NF data into multiple tables? Note: on the following slides, you will see illustrations of tables. While these examples are similar to the design your class has selected, they are probably not exactly the same. When normalizing your database, use the designs your class has selected, including the designated data types, data sizes and other specifications.

2 The Challenge: Analyze and then normalize the design of tblPerson by moving some of the fields (and their data) to new, normalized tables.

3 Note: The column names, data types, and null properties in the diagram below may be different from the design chosen by your class. Preparation Backup It is generally safer – and wiser – not to change the original data. Before making any changes to the data you have imported … Make a copy* of tblPersonSTAGING. Name it tblPersonBACKUP. Verify that tblPersonSTAGING is 100% identical to the original table in both data definition and the data itself. You now have two tables: tblPersonBACKUP and tblPersonSTAGING * See BackupTables.ppt for instructions on making a copy of a table. Staging

4 SOLUTION to the CHALLENGE
The Final Design of Each Table SOLUTION to the CHALLENGE Start with functional dependency analysis. Redesign the data model and the physical data model based on those functional dependencies. Create the new (empty) tables (seen at right), including tblPerson (new).

5 Migration Steps INSERT INTO tblMembershipType (MembershipType) SELECT DISTINCT (MembershipType) FROM [dbo].[tblPersonSTAGING]; Generally, three steps are needed to migrate some fields (but not all fields) to a new table: INSERT data from the STAGING table into the parent table. Add a FK to the STAGING table. UPDATE the FK field in the STAGING table. Repeat steps 1-3 for tblMembership Add the FK However, do not create a relationship to tblPersonSTAGING. tblPersonSTAGING is just a transition table, not a production table. Non-normalized, original table MembershipTypeID MembershipID UPDATE tblPersonSTAGING SET MembershipTypeID = mt.MembershipTypeID FROM tblMembershipType mt INNER JOIN tblPersonSTAGING pSTGNG ON mt.MembershipType = pSTGNG.MembershipType

6 Summary/Recap of the Previous Slide Example: tblPersonSTAGING  tblMembershipType
See the illustration on the previous slide Create an empty tblMembershipType with all the fields needed. Include a MembershipTypeID identity field as the primary key. INSERT INTO … tblMembershipType the appropriate data. Verify that the INSERT was successful. Add a MembershipTypeID foreign key field to tblPersonSTAGING. UPDATE the MembershipTypeID foreign key (in tblPersonSTAGING). Verify that the UPDATE was successful.

7 Migration: COMPLETE! Just in case you discover later that something went horribly wrong … Keep tblPersonBACKUP Keep tblPersonSTAGING Keep your INSERT and UPDATE commands in a script With these files, you may be able to rapidly fix the problem.


Download ppt "Normalizing an Existing Table"

Similar presentations


Ads by Google