Here’s a good one I think. To start off with, I don’t really know what a trigger is, which might become obvious now.
Are triggers good for maintaining backwards compatibility between database schemas?
Say I have a 1-to-many relationship in version 1. In version 2 this has been changed to a many-to-many. Would a properly implemented trigger be able to handle this so as to allow both versions to run on the same database? Is it a good idea?
Yes, you could do this by utilizing a INSTEAD OF trigger for inserts, updates, and deletes on a view for the old version. To make this more clear, let’s consider the following example:
First you would create a view to mimic the old version of the B table. The tricky thing would be deciding on which of the AB relations to show to the old application. One option would be to add a
primary_bcolumn of typebitto theABtable. The view below uses this optionNext you would create triggers on the view to handle inserts and updates.
You would do something similar for instead of update, except that you would have to manage the change in A to B links by deleting and adding rows in AB. I haven’t checked this code out for errors yet, but I will in the next hour or so and post an update if needed.