How to add “on delete cascade” constraints?

前端 未结 3 650
无人共我
无人共我 2020-11-28 02:55

In PostgreSQL 8 is it possible to add ON DELETE CASCADES to the both foreign keys in the following table without dropping the latter?

# \\d scor         


        
3条回答
  •  孤独总比滥情好
    2020-11-28 03:39

    Based off of @Mike Sherrill Cat Recall's answer, this is what worked for me:

    ALTER TABLE "Children"
    DROP CONSTRAINT "Children_parentId_fkey",
    ADD CONSTRAINT "Children_parentId_fkey"
      FOREIGN KEY ("parentId")
      REFERENCES "Parent"(id)
      ON DELETE CASCADE;
    

提交回复
热议问题