加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在PostgreSQL中删除带有外键的行

发布时间:2020-12-13 16:44:43 所属栏目:百科 来源:网络整理
导读:我想删除包含外键的行,但当我尝试这样的: 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)
我想删除包含外键的行,但当我尝试这样的:
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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读