Published on

Published in: Technology, Health & Medicine
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Fundamental to Database Design Gives a place to start when you have a mess of data
  • Normalization

    1. 1. Database Normalization <ul><li>TJ Racoosin </li></ul><ul><li>2 Dec 1998 </li></ul><ul><li>CPCUG Access SIG </li></ul>Racoosin Solutions 703 849-1997
    2. 2. Overview <ul><li>Introductions </li></ul><ul><li>The Normal Forms </li></ul><ul><li>Primary Key </li></ul><ul><li>Relationships and Referential Integrity </li></ul><ul><li>When NOT to Normalize </li></ul><ul><li>Real World Exercise </li></ul><ul><li>Resources </li></ul>Racoosin Solutions
    3. 3. Introductions <ul><li>TJ Racoosin </li></ul><ul><li>You </li></ul><ul><ul><li>Are you familiar with normalization? </li></ul></ul><ul><ul><li>Used the relationship window ? Enforce referential integrity? Cascade Delete? </li></ul></ul><ul><ul><li>Any issues with normalizing data? </li></ul></ul>Racoosin Solutions
    4. 4. Why Normalize? <ul><li>Flexibility </li></ul><ul><ul><li>Structure supports many ways to look at the data </li></ul></ul><ul><li>Data Integrity </li></ul><ul><ul><li>“ Modification Anomalies” </li></ul></ul><ul><ul><ul><li>Deletion </li></ul></ul></ul><ul><ul><ul><li>Insertion </li></ul></ul></ul><ul><ul><ul><li>Update </li></ul></ul></ul><ul><li>Efficiency </li></ul><ul><ul><li>Eliminate redundant data and save space </li></ul></ul>Racoosin Solutions
    5. 5. Normalization Defined <ul><li>“ In relational database design, the process of organizing data to minimize duplication. </li></ul><ul><li>Normalization usually involves dividing a database into two or more tables and defining relationships between the tables. </li></ul><ul><li>The objective is to isolate data so that additions, deletions, and modifications of a field can be made in just one table and then propagated through the rest of the database via the defined relationships .” - Webopedia, </li></ul>Racoosin Solutions
    6. 6. Another Definition <ul><li>&quot;Normalization&quot; refers to the process of creating an efficient, reliable, flexible, and appropriate &quot;relational&quot; structure for storing information. Normalized data must be in a &quot;relational&quot; data structure. - Reid Software Development, </li></ul>Racoosin Solutions
    7. 7. The Normal Forms <ul><li>A series of logical steps to take to normalize data tables </li></ul><ul><li>First Normal Form </li></ul><ul><li>Second </li></ul><ul><li>Third </li></ul><ul><li>Boyce Codd </li></ul><ul><li>There’s more, but beyond scope of this </li></ul>Racoosin Solutions
    8. 8. First Normal Form (1NF) <ul><li>All columns (fields) must be atomic </li></ul><ul><ul><li>Means : no repeating items in columns </li></ul></ul>Solution: make a separate table for each set of attributes with a primary key (parser, append query) Customers CustomerID Name Orders OrderID Item CustomerID OrderDate Racoosin Solutions
    9. 9. Second Normal Form (2NF) <ul><li>In 1NF and every non-key column is fully dependent on the (entire) primary key </li></ul><ul><ul><li>Means : Do(es) the key field(s) imply the rest of the fields? Do we need to know both OrderID and Item to know the Customer and Date? Clue: repeating fields </li></ul></ul>Solution: Remove to a separate table (Make Table) OrderDetails OrderID Item Orders OrderID CustomerID OrderDate Racoosin Solutions
    10. 10. Third Normal Form (3NF) <ul><li>In 2NF and every non-key column is mutually independent </li></ul><ul><ul><li>means : Calculations </li></ul></ul><ul><li>Solution: Put calculations in queries and forms </li></ul>OrderDetails OrderID Item Quantity Price Put expression in text control or in query: =Quantity * Price Racoosin Solutions
    11. 11. Boyce-Codd Form (3NF) - Examples <ul><li>A more restricted version of 3NF (known as Boyce-Codd Normal Form ) requires that the determinant of every functional dependency in a relation be a key - for every FD: X => Y, X is a key </li></ul><ul><li>Consider the following relation: STU-MAJ-ADV ( Student-Id , Major, Advisor) Advisor => Major, but Advisor is not a key </li></ul><ul><li>Boyce-Codd Normal Form for above: STU-ADV ( Student-Id , Advisor) ADV-MAJ ( Advisor , Major) </li></ul>2/16/98 10 MGS 404 2/16/98 10 Kumar Madurai:
    12. 12. Primary Key <ul><li>Unique Identifier for every row in the table </li></ul><ul><ul><li>Integers vice Text to save memory, increase speed </li></ul></ul><ul><ul><li>Can be “composite” </li></ul></ul><ul><ul><li>Surrogate is best bet! </li></ul></ul><ul><ul><ul><li>Meaningless, numeric column acting as primary key in lieu of something like SSN or phone number - (both can be reissued!) </li></ul></ul></ul>Racoosin Solutions
    13. 13. Relationships <ul><li>One to many to enforce “Referential Integrity” </li></ul>Two “foreign” keys make a composite primary key and “relate” many to many tables A look up table - it doesn’t reference any others Racoosin Solutions
    14. 14. Table Prefixes Aid Development <ul><ul><li>First, we’ll get replace text PK with number </li></ul></ul><ul><ul><li>The Items table is a “look up” with tlkp prefix </li></ul></ul><ul><ul><ul><ul><li>tlkp “lookup” table (no “foreign keys”) </li></ul></ul></ul></ul><ul><ul><li>OrderDetails is renamed “trelOrderItem” a “relational” table </li></ul></ul><ul><ul><ul><li>trel “relational” (or junction or linking) </li></ul></ul></ul><ul><ul><ul><ul><li>two foreign keys make a primary </li></ul></ul></ul></ul>tblOrders OrderID CustomerID OrderDate OrderDetails OrderID Item trelOrderItem OrderID ItemID tlkpItems ItemID ItemName Racoosin Solutions
    15. 15. Referential Integrity <ul><li>Every piece of “foreign” key data has a primary key on the one site of the relationship </li></ul><ul><ul><li>No “orphan” records. Every child has a parent </li></ul></ul><ul><ul><li>Can ’t delete records from primary table if in related table </li></ul></ul><ul><li>Benefits - Data Integrity and Propagation </li></ul><ul><ul><li>If update fields in main table, reflected in all queries </li></ul></ul><ul><ul><li>Can’t add a record in related table without adding it to main </li></ul></ul><ul><ul><li>Cascade Delete : If delete record from primary table, all children deleted - use with care ! Better idea to “archive” </li></ul></ul><ul><ul><li>Cascade Update : If change the primary key field, will change foreign key </li></ul></ul>Racoosin Solutions
    16. 16. When Not to Normalize <ul><li>Want to keep tables simple so user can make their own queries </li></ul><ul><ul><li>Avoid processing multiple tables </li></ul></ul><ul><li>Archiving Records </li></ul><ul><ul><li>If No need to perform complex queries or “resurrect” </li></ul></ul><ul><ul><li>Flatten and store in one or more tables </li></ul></ul><ul><li>Testing shows Normalization has poorer performance </li></ul><ul><ul><li>“ Sounds Like” field example </li></ul></ul><ul><ul><li>Can also try temp tables produced from Make Table queries </li></ul></ul>Racoosin Solutions
    17. 17. Real World - School Data Student Student Previous Current Last First Parent 1 Parent 2 Teacher Teacher Smith Renee Ann Jones Theodore Smith Hamil Burke Mills Lucy Barbara Mills Steve Mills Hamil Burke Jones Brendan Jennifer Jones Stephen Jones Hamil Burke …. Street Address City State Postal Code Home Phone 5551 Private Hill Annandale Virginia 22003- (703) 323-0893 4902 Acme Ct Annandale Virginia 22003- (703) 764-5829 5304 Gains Street Fairfax Virginia 22032- (703) 978-1083 …. First Year Last Year Age Program Enrolled Attended Birthday inSept Map Coord Notes PF / 0 0 6/25/93 5 22 A-3 PF 96/97 0 8/14/93 5 21 F-3 PH 96/97 0 6/13/94 4 21 A-4 Racoosin Solutions
    18. 18. One Possible Design Racoosin Solutions
    19. 19. Books <ul><li>Access97 Developers Handbook Litwin,Getz & Gilbert </li></ul><ul><ul><li>Chapter 4 </li></ul></ul><ul><li>Access and SQL Server Developers Handbook Viescas, Gunderloy and Chipman </li></ul><ul><ul><li>Chapter 2 </li></ul></ul><ul><li>Access97 Expert Solutions Lezynski </li></ul><ul><ul><li>Chapter 10 </li></ul></ul>Racoosin Solutions
    20. 20. Internet <ul><li>Papers </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li>Slides </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li> </li></ul>Racoosin Solutions