Jump to content

How to prevent double booking


Kenny_Luck

Recommended Posts

I am facing a problem with double booking , i don't know where to start to write the code that a customer can't rental the same car at for the same day. For example, if a customer choose to book car A from 1/8/2018 till 10/8/2018 , how do i avoid that other customer won't book on the date 1/8/2018 or even 2/8/2018 and so on. Pls help me is quiet urgent

Link to comment
Share on other sites

Easiest way...

+--------------+                                +-------------+
|   Car        |                                | customer    |
+--------------+                                +-------------+
| car_id  (PK) |--+                          +--| cust_id (PK)|
| reg_no       |  |                          |  | name        |
| make         |  |                          |  +-------------+
| model        |  |                          |
+--------------+  |                          |
                  |                          |
                  |   +-------------------+  |
                  |   |  booking          |  |
                  |   +-------------------+  |
                  |   |  booking_id  (PK) |  |
                  +--<|  car_id      (UQ) |  |
                      |  hire_date   (UQ) |  |
                      |  cust_id          |>-+
                      +-------------------+

In the booking table (car_id, hire_date) is defined as a unique key and a record is written for each day that the car is hired. Because the key is unique, booking it to another customer on one of those dates will throw an error and the transaction should be cancelled.

Edited by Barand
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.