Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing a FK delete rule in Oracle without dropping and recreating it?

Is there a way to change a table FK delete rule in Oracle better than dropping and then adding it again?

I'm currently using:

alter table A
drop constraint my_fk;

alter table A
add constraint my_fk
foreign key (id)
references B(id)
ON DELETE SET NULL;

As you can see, I already have a FK constraint but it had no delete rule on it. I just want to add an ON DELETE SET NULL rule, and that's what I came up with so far, but I'm feeling it should be simpler.

like image 796
Greg Avatar asked Dec 07 '10 09:12

Greg


1 Answers

No other way, except drop and re-create constraint. Oracle have syntax ALTER TABLE x MODIFY CONSTRAINT, but it can be used only for change state of constraint.

http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_3001.htm

like image 78
Michael Pakhantsov Avatar answered Sep 21 '22 09:09

Michael Pakhantsov