I need some normalization help

Discussion in 'Databases' started by absentx, Nov 10, 2011.

  1. #1
    I tell ya, this programming stuff is great. Just when you think you are getting somewhere, you stumble across a page in a book about normalization and realize all your db efforts during the learning period have been for not!

    Okay so I want to make sure this new db I am making for an application is normal to the best of my abilities.

    I have a reservation system that I want to be organized by the units rented...we have ten units, or cabins.

    so, I have unit_reservations as a table. My thought is to make this table have "id", "cabin_rented", "begin_date", "end_date" and a unique "reservation_id"

    Then in my customer table I can have a "reservation_id" for each customer along with all their pertinent info

    My thought here is that it keeps my unit_reservations seperate so I can always use the unit_reservations table for queries regarding when each individual unit is taken and so on...

    This way the customer data is kept completely seperate from the cabin date, but we have the unique reservation id connecting them


    Is this in any way resembling the second normal form? Heck even first????? Just trying to get a grasp on this concept that came out of nowhere and put me back to the 1st grade.
     
    absentx, Nov 10, 2011 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    Good idea, but ...

    reservation_id could be customer_id. You don't need a separate one.

    To check "cabin_rented", check begin_date and end_date. If they're blank, it's not rented. If they fall outside of the date range you want to check to see if it's rented for, it's not rented for that date range. If you want to know if it's currently rented, check for begin_date or end_date being now. If you want to check whether it's ever been rented, check for either one being not blank. (We use a date FAR in the past - 19th century - as a "blank" date, since you can't have a really blank date.)

    So that would save you two fields, one in each table. Not only does normalization mean not storing the same data in more than one place, it means not storing data you can calculate.
     
    Rukbat, Nov 15, 2011 IP
  3. shanmugappriya

    shanmugappriya Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Normalization usually involves dividing large tables into smaller (and less redundant) tables and defining relationships between them.The goal of database normalization is to decompose relations with anomalies in order to produce smaller, well-structured relations.
     
    shanmugappriya, Nov 18, 2011 IP
  4. mmerlinn

    mmerlinn Prominent Member

    Messages:
    3,197
    Likes Received:
    819
    Best Answers:
    7
    Trophy Points:
    320
    #4
    Normalization should be used when you are storing the same data in 2 or more different locations. In theory, no data should be stored in more than one location, although in some rare instances that is the best way.
     
    mmerlinn, Nov 23, 2011 IP