Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Database Foundations Introduction to Data, Databases and SQL Introduction to Data Types

how do i store availability efficiently in a relational database? For example a room booking system

how do i enter availability of a room type? or should i be looking to only store when the bookings for a room.

2 Answers

You could have a table of bookings, with a key based on the table of rooms. The rationale for that would be that each room could have many bookings, but each booking can only have one room. i.e. a many-to-one relationshop.

Hi James Thanks for you reply, i guess your advise above would take care of the bookings associated to the rooms, i am struggling with how i display the availability presumably this would be done via code which would then block out any dates from the bookings table.

For example

Define a open period - 1/1/14 - 1/4/14 for each room in the rooms table

output this via a calendar which shows availability to the user i.e. For each day between date open to date close would be shown as available ( green colour block) in the output of the query

run a look up query for any dates in the bookings table between this period and mark them as booked ( red colour block)

output query results to web page.

Do you think would this be the best way to shown available and booked blocks or should i be doing something else?

thanks