ORACLE - How to add a check constraint that looks at another table?

时间:2016-08-31 18:16:01

标签: oracle triggers constraints

I am having a "Mutating" trigger error on two tables. Basically, table A has a trigger to UPDATE table B on insert or update. However, table B has a trigger to check that the value of a column in table A is in a valid range.

How can I add a constraint to table B to check that the value of some column in table A is in a valid range? I have tried creating a function to do this but I get an error saying "invalid identifier".

ALTER TABLE MYSCHEMA.TABLE_A ADD 
CONSTRAINT MY_TRIGGER
CHECK (MYSCHEMA.MYTABLE_A_FK_CHECK(FK_TBLA_ID) IN (3,4,5))
ENABLE
VALIDATE

Where the function checks a "status_id" column in table a where tableA id = tableB_fk_id.

I get this error when I try to create this:

ORA-00904: "MYSCHEMA.MYTABLE_A_FK_CHECK": invalid identifier

Is there any possible way to do this? I have tried using triggers but when an update occurs in table A, I get the "mutating" table trigger error. Is there any possible way to accomplish something like what I am trying to do?

0 个答案:

没有答案
相关问题