I had made two tables with the following fields:
TABLE 1: "Bookings"
FIELD: "fk_flight_number"
FIELD: "date_of_reservation"
TABLE 2: "Flights"
FIELD: "flight_number"
FIELD: "date_of_departure"
I want to add a condition, just for the consistency of my data. I want to check ON INSERT:
1) in Bookings
- fk_flight_number
must exists in Flights
2) date_of_reservation
must be smaller (<
) from date_of_departure
.
How to do that? I have read about something similar and the keyword was TRIGGER. I think in my case it must be the same. Can you show me how to refer the second table? The logical conditions are not important - I can handle it. I need some snippet, because I don't know how to start writing the TRIGGER I need for. Or If you know some article describing similar problem - I will appreciate it too. Thank a lot. Of cource I'm not 100% sure that the best approach is TRIGGER. Any other advice will be appreciated too. One more time - thank you!
fk_flight_number
as a foreign key onFlights.flight_number
then the first condition will be satisfied: it will be assured by InnoDB. Regarding the second one: how do you insert data into Bookings (stored proc, fixed SQL from an application or sometimes manually as well)? – dezso Nov 12 '12 at 10:40