Thursday, April 21, 2011

Why need 2NF?

Just wondering sometime the 2NF may not be necessary.

Option 1. ORDERS {orderId (pk), custId (fk), total, date, status, ...}
   PARTS {orderId (pk), partsId (pk), qty, unitPrice, description, ...}

Option 2. ORDERS {orderId (pk), custId, total, date, status, ...}
   ORDER_PARTS {orderId (pk)(fk), partsId (pk)(fk), qty, ...}
   PARTS {partsId (pk), unitPrice, description, ...}

Most people like Option 2, I think, because it is 2NF but I think Option 1 is better because it will be simpler and faster when we query them. Why we need 2NF in cases like this?

From stackoverflow
  • You want the 2nd normal form because with option 1, a part doesn't exist unless it belongs to an order.

    5YrsLaterDBA : You are right, but it is true sometimes. when we received a new order, some parts might be new to us and no record for them.
  • In Option 1, when the user wants to change the description of a part, you will have to change it on ALL the orders associated to that part. Don't you feel the bad smell?

    5YrsLaterDBA : You are right, too.
  • As a beginning DBA, you should be putting everything into third normal form. That means, every column in a row depends on:

    • the key (1NF).
    • the whole key (2NF).
    • nothing but the key (3NF).

    With experience, you can opt to revert sometimes to 2NF for various reasons (usually speed), but that's not something I'd be worrying about as a beginner.

    unforgiven3 : Amen. Agreed completely. +1.
    eKek0 : +1 for the excelent brief description of the normal forms!
    marc_s : "The key, the whole key, and nothing but the key, so help me Codd." :-)

0 comments:

Post a Comment