I'm running maintenance on a database program with no foreign key constraints, even though it really should have...
There is a Logging table which has a ParentID column, and a ParentType column. The entry in the ParentType column determines which table ParentID references.
What I'm looking for is for ideas on the best way to add this input-dependent foreign key constraint... abomination...
I'd love to be able to just throw out the whole back end of this program and start again, but it's already unreliable as hell without me breaking everything. Tightening up the back end seems to be my best best at this point. The only real alternative seems to be to throw out the entire program.
So, yeah, ideas on the best way to constrain the data in this column on the SQL side?
EDIT: I can tell this unclear already...
Right, so I have have the Logging table, then TableOne and TableTwo. If the row being entered into Logging tries to add a row with 1 in the ParentType column, then the ParentID must appear in TableOne, if ParentType is 2, ParentID must appear in TableTwo.