I have a problem with multiple cascade path error. Here are my tables:
Table (Companies)
CompanyCode (PK)
….
Table (Aircraft)
AircraftRegistration (PK)
OwnerCode (FK to CompanyCode)
OperatorCode (FK to CompanyCode)
….
I simply want to update the ownercode and operatorcode foreign keys in the aircraft table when I update the primary key in companies.
Is the correct way to get around this problem to use triggers?
You can add ON UPDATE CASCADE to your foreign key definitions, then the values will automatically be updated if the referenced key (i.e. Companies.CompanyCode) is changed.
EDIT: But as you noted in the comments, this won’t work for tables that have two foreign keys referencing the same column, so for those cases you would have to use a trigger or do all your updates in a ‘controlled’ manner, such as through a stored procedure that updates the referencing columns. Which approach is better depends on your application design and how your database is used.