3

I have two tables TableA and TableB. Now TableA has 2 columns: ID & Name, TableB has 3 columns: ID, Name, & TableAID. Now there is a foreign key constraint from TableA.ID = TableB.TableAID. I need to be able to allow for TableB.TableAID to either use values from TableA.ID or TableB.ID, hence multiple foreign key constraints on a single column and I need it to allow either or. Thanks!

1
  • Can you use a NULL in TableB.TableAID as an indication that you should use TableB.ID? That would mean that the TableB.ID you want to stick in there would be the one on the record already which probably is not the case... Commented Apr 12, 2011 at 15:02

1 Answer 1

6

That is a clear sign of a bad design. You should never need to do this and if you do then you need to rethink your design.

You cannot make a field be associated with two different FKs.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah I can only add constraints to these tables, I can't change the design of the tables or remove any constraints. :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.