I am working on a batch processing application that allows users to submit requests for information about particular vehicles. Users can submit a request either using a VIN or a License Plate/State combination. I proposed the following table structure:
VehiclesToBeProcessed
vehicle_id(fk)|user_id(fk)|status|start_time
Vehicles
vehicle_id|VIN|plate|state
My colleague argued that this was poor design, because every record in Vehicles would either have a null VIN field, or null plate and state fields. Instead, they proposed the following:
VehiclesToBeProcessed
vehicle_id(fk)|user_id(fk)|status|start_time
Vehicles
vehicle_id(pk)|field|value
where an entry in Vehicles would either consist of one row for a vin:
1|"vin"|"123
or two rows for a plate/state:
2|"plate"|"abc 123" 2|"state"|"NY"
I thought that the first solution would be much easier to query without having any significant downside. Which design should be preferred? Are guaranteed null fields really an indicator of bad design?
vehicle_id(pk)is a primary key , then you cannot have 2 rows with the same vehicle_id. Also, as far as I know , every car must have VIN (which may be unknown), but not a plate. In addition, plate number changes (can change) over the time.