我想删除包含外键的行,但当我尝试这样的:
DELETE FROM osoby WHERE id_osoby='1'
我得到这个声明:
ERROR: update or delete on table “osoby” violates foreign key constraint “kontakty_ibfk_1” on table “kontakty”
DETAIL: Key (id_osoby)=(1) is still referenced from table “kontakty”.
如何删除这些行?
要自动化,可以使用ON DELETE CASCADE定义外键约束。
我引用 the manual of foreign key constraints:
原文链接:/postgresql/193376.html我引用 the manual of foreign key constraints:
CASCADE
specifies that when a referenced row is deleted,row(s) referencing it should be automatically deleted as well.