0

I have a database with three tables:

Tab1
IdTab1
DataTab1

Tab2
IdTab2
DataTab2

Tab3
Id
RifTab (contains 1 or 2)
IdRifTab (contanins the rif id of one of the two tables)

Assuming that IdTab1 and IdTab2 are primary keys, is it possible to create a foreign key for IdRifTab with the two tables depending on value of RifTab?

I know that probably I'm asking for impossible but I'm a self-taught and I learned that asking is the better way for learning.

I want to precise that I looked for a solution to the problem and I found this: One Foreign Key with 2 References Table but my case is different: I need to distinguish the ids of a table from those of the other.

Any suggest is appreciated

Thank you for your time.

Community
  • 1
  • 1
genespos
  • 3,211
  • 6
  • 38
  • 70
  • continuing to search I found this: http://stackoverflow.com/questions/20692529/attempting-to-avoid-polymorphic-associations and I think is a bit over my current knowledge. I'll try to understand criteria to work with polimorphic associations. The prolem is that my real db has 5 tables with ids to link and not two like in the example... Thanks to everybody – genespos Mar 03 '15 at 14:35

1 Answers1

0

this is a similar question and you might want to take a look. Conditional Foreign Key to multiple tables

Even that I myself don't think that this is a nice elegant solution. Maybe you can review the database schema and come up with a better solution :).

Community
  • 1
  • 1
bbakiu
  • 281
  • 3
  • 11