在PostgreSQL中删除带有外键的行

前端之家收集整理的这篇文章主要介绍了在PostgreSQL中删除带有外键的行前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想删除包含外键的行,但当我尝试这样的:
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

CASCADE specifies that when a referenced row is deleted,row(s) referencing it should be automatically deleted as well.

原文链接:/postgresql/193376.html

猜你在找的Postgre SQL相关文章