database - Foreign Key referring one field of two tables in oracle -


i trying set foreign key refering different tables.

imagine tables:

active_card((primary key)num_id number, num_card number,is_active varchar2);

tmp_card((pk)num_card number, reg_date date);

definitive_card((pk num_card number, name varchar, create_date date)

so num_card foreign key of active_card. problem how refer both tables (tmp_card , definitive_card) in active_card.

best regards,

let's explain why wouldn't idea , go there:

1st let's rdbms lets this.

so have fk in active_card relates both definitive_card , tmp_card.

now lets have definitive_card#s of 123, 456 , tmp_card#s of 123, 789

foreign keys enforce referential integrity. 123 ok have since exists in both. 456 , 789 wouldn't doesn't exist in both tables.

but isn't wanted. indicated needed in either table not both indicated in comment stating: *in order have entry in active_card must exist entry in definitive_card or in tmp_card*

so since don't want same card_number in both have 2-3 choices:

  1. put card_numbers in separate table , though associative table join active_card
  2. put 2nd card_number column in active_card , depending on field populated tells table go additional information.
  3. put fields in definitive_card , tmp_card in same table

each of these options have own list of pros , cons: without understanding business requirements, couldn't best situation.

we can trying not work in rdbms; of 3 options above , meet requirements of being able add appropriate foreign keys


Comments