Oracle Sql Check Constraint != Other Table
Solution 1:
It appears from the text of your syntactically incorrect check constraint, that you want to enforce a multi-table check constraint. The only way to do this in Oracle (and maybe any RDBMS) is with a trigger. You cannot reference multiple tables in a check constraint.
However, depending upon your Oracle version, and according to the Oracle constraint documentation, you might be able to define a rather complex foreign key constraint as this implies:
You cannot define a foreign key constraint in a CREATE TABLE statement that contains an AS subquery clause. Instead, you must create the table without the constraint and then add it later with an ALTER TABLE statement
Solution 2:
If your primary keys are numbers which are obtained from sequences, the best way to accomplish what you're trying to do is to get the ID numbers for both tables from the same sequence. If you do it this way you're guaranteed that they won't duplicate each other, and you eliminate the need for a bunch of expensive logic to verify this condition.
Best of luck.
Post a Comment for "Oracle Sql Check Constraint != Other Table"