Bertaud
Bertaud

Reputation: 2918

Update a constraint in postgresql 9.1 database

I would like to change "on delete restrict" to "on delete cascade": how can i do it ?

ALTER TABLE T1
ADD CONSTRAINT fk_T1 FOREIGN KEY (id1)
  REFERENCES T2 (id1) MATCH SIMPLE
  ON UPDATE RESTRICT ON DELETE RESTRICT;

Upvotes: 1

Views: 95

Answers (1)

namero999
namero999

Reputation: 3002

You have to drop it and recreate it.

ALTER TABLE T1 DROP CONSTRAINT fk_T1;

ALTER TABLE T1 ADD CONSTRAINT fk_T1 FOREIGN KEY (id1)
REFERENCES T2 (id1) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE;

Upvotes: 5

Related Questions