Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Check Constraint question

727255Oct 10 2009 — edited Jan 7 2012
Hi,

I have a question regarding creating a constraint against two tables. I have an FK in table_A that should check the constraint against two related tables. Table_A is the table that holds the FK and tables B and C hold the PK back to table A. The problem is with my constraint FK I receive the message ORA-02251: subquery not allowed here. I need to ensure that the AFK contains the FK value that is in either TABLE_B or TABLE_C .

In my create statement I have

CREATE TABLE TABLE_A
(_PK INTEGER NOT NULL ENABLE,
_FK INTEGER NOT NULL ENABLE,
CONSTRAINT A__PK PRIMARY KEY (_PK) ENABLE,
CONSTRAINT A__FK CHECK (_FK IN (SELECT FK FROM TABLEB UNION SELECT FK FROM TABLEC)) ENABLE
);

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 4 2012
Added on Oct 10 2009
9 comments
962 views