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中删除带有外键的行全部内容,希望文章能够帮你解决在PostgreSQL中删除带有外键的行所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)