I have a child table in oracle that has two foreign key columns, relating to two different parent tables. I want to create a constraint that says the child must have at least one of those parents - e.g.
ALTER TABLE table_name
ADD CONSTRAINT constraint_name
FOREIGN KEY (column1)
REFERENCES parent_table (column1)
OR
FOREIGN KEY (column2)
REFERENCES parent_table_2 (column1)
This won't work with a foreign key constraint because that can only relate to one parent table - is it possible to do this with a check constraint instead?
Dmitry Grekov :
Foreign key constraints ensure the referential integrity, not mandatory values.\nI think you have to have to separate FK contraints and additional check constraint like this:\n\nalter table table_name \n add constraint c_check_cols \n check(column1 is not null or column2 is not null);\n",
2018-08-10T06:08:07