I am in the middle of designing the dB for school project- airline ticketing database.(Using MySQL workbench)
So far, I came up with the following design:
Here are couple things I can't figure out:
- Is it good idea to have Foreign keys as non-int values (such as
Varchar
) ?? - Database needs to somehow keep track of Number of seats booked & Number of passengers on board for particular flight. Have no idea where to place those attributes.
- How to make sure that Arrival City and Departure City (from
Flight
table) are different for particular flight ?
Best Answer
1- Prefer
int
. Firstly it is better to have keys with shorter lengths. And later if you update a flight status, you can.2- You can have
TotalSeats
inAirplane
table and perhaps write anSQL
query that by examiningStatus
, you can figure out booked seats and passengers onboard. (Consider schema improvements as suggested by @galuano13- You can write a trigger that makes sure they are not same, or perhaps validate it in the code.