Kenny_Luck Posted September 16, 2019 Share Posted September 16, 2019 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted September 16, 2019 Share Posted September 16, 2019 (edited) 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 September 16, 2019 by Barand Quote Link to comment Share on other sites More sharing options...
Kenny_Luck Posted September 16, 2019 Author Share Posted September 16, 2019 so if i wan to like rent the car starting with 11/8/2018 is still possible right ?? Quote Link to comment Share on other sites More sharing options...
Barand Posted September 16, 2019 Share Posted September 16, 2019 (edited) Yes, so long as there is no record for another customer containing car A | 2018-08-11 (There is a tutorial on resource booking in my signature) Edited September 16, 2019 by Barand Quote Link to comment Share on other sites More sharing options...
Kenny_Luck Posted September 16, 2019 Author Share Posted September 16, 2019 i see thanks , if i got any problem i will ask it , thanks for your help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.