Data Modeling Table Relationships

Posted on 2012-08-26
Last Modified: 2012-08-28
I'm creating a Data Model, and I'm trying to get it to 3NF.
I keep reasoning myself into a circular model, and I don't want that.

That being said, I was hoping to get some other opinions.
THe attached data model completes the list of data facts I require.
I'm having issues setting the relationships.

Here's the facts I know:
1.  There are multiple locations
2. Each location has 1 or more dates
3. Each Location has 1 or more spaces
4. Each space requires a reservation
5. Each reservation is a space per date per location

Each table has the dataparts I require to move forward.
Any recommendations on how to make this data model fit better would be greatly appreciated.

Thank you.
Question by:Evan Cutler
    LVL 45

    Accepted Solution

    Hi Evan,

    If you think of this in terms of a Hotel and Hotel reservations it might make more sense.

    1. There are multiple hotels
    2. Each hotel has 1 or more dates
    3. Each hotel has 1 or more rooms
    4. Each room requires a reservation
    5. Each reservation is a room per date per hotel

    That normalizes rather well.  Your tables are:

    Hotel -- Hotel ID and demographics.
    Hotel Dates -- ID column, Hotel ID, and dates.
    Rooms -- ID column, Hotel ID, room descriptions
    Reservations -- ID Column, Room ID, Date field.

    Hotel Dates is simply table of dates of valid reservations for the hotel.

    LVL 9

    Author Comment

    by:Evan Cutler
    Hi Kent,
    Thanks so much...

    Hey, in Reservations, is Date field a FK to HotelDates?
    LVL 17

    Expert Comment

    Apart from the showdate in your reservation table (which probably is derived from the ShowDates reference), I don't see any problem with 3NF here ... assuming that multiple reservations for the same date and space are allowed, you need the additional PK field in the reservations table. If only one reservation for a date/space combination can be made, drop the PK field and you should be fully normalized to 3NF there ... assuming you have 1NF and 2NF already, the only additional requirement is that no fields may be derivable from other means than the primary keys, which isn't the case for the other data fields.

    So, adding the 1:n relationships between the location and both dates and spaces, and 1:n between both dates and spaces and the reservations table should solve your design ...

    Also, from personal experience, while normalization is a good idea, there are occasions where full normalization may cause performance or design issues in other places, so using it as a starting point is good, but don't treat it as a religion ... ;) If you can get your program to work better with slight tweaks to the data model, weigh the pros and cons and go with the solution that is the better one overall...
    LVL 45

    Expert Comment

    >> Hey, in Reservations, is Date field a FK to HotelDates?

    That depends on your implementation.  If HotelDates contains all of the dates when the Hotel is open (or accepting reservations), a Foreign Key relationship exists.  If the table contains the dates when the Hotel is closed, full, (not accepting reservations for any reason) there is a "backward" relationship, but no real foreign key.  And if the table contains a range of dates (start_date -> end_date) of either accepting or not accepting reservations, there is no foreign key.  BUT, they all resolve with the correct SQL.  The difference is that you have to code the SQL to the problem, where if there is a FK relationship, the DBMS maintains it for you.

    LVL 9

    Author Closing Comment

    by:Evan Cutler
    This helped alot.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now