Skip to Main Content

Oracle Database Express Edition (XE)

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!

Help with a check constraint

727255Oct 10 2009 — edited Nov 5 2009
I have inadvertantly posted this in the wrong section, so I am reposting this in the SQL section and marking this one as answered.

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

Edited by: user11947229 on Oct 10, 2009 11:43 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 3 2009
Added on Oct 10 2009
3 comments
1,312 views