I’m developing a relational system, that involves the following entities:
- Enquiry
- Quote
- Supplier
- Town
- Vehicle
Enquiry is the main model for the system and contains foreign keys for all the other entities.
Now what I’m concerned of is for example if the client goes and deletes a Town – the Enquiry record has a reference to the town id and would therefore break the system. Similarly if the client goes and deletes a Vehicle then Supplier records would break.
So what is the best way to handle deletions of relational records? Should we even offer the facility to delete records (perhaps have a enabled/disabled boolean switch instead?).
Similarly when renaming records how can we preserve original data for older records (for example if the client decided to rename Vehicle “Bus” to “Minibus”).
Only allow deletions of orphaned records? If I delete records from
ENQUIRYthat relate to a specific Vehicle, then someone should be able to remove that vehicle. But not before the child references have been dealt with… Pretty easy to handle using NOT EXISTS:This is why you make the name/description separate from the primary key for using as a foreign key. If the VEHICLES table has two columns–vehicle_id and vehicle_description–then the description can change without referential integrity impact because you define the foreign key on the vehicle_id column.