绕过外键约束强制删除mysql

编程入门 行业动态 更新时间:2024-10-24 18:22:49
本文介绍了绕过外键约束强制删除mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试从数据库中删除除一个之外的所有表,但最终出现以下错误:

I'm trying to delete all tables from a database except one, and I end up having the following error:

无法删除或更新父行:外键约束失败

Cannot delete or update a parent row: a foreign key constraint fails

当然,我可以反复试验以查看这些关键约束是什么,并最终删除所有表,但我想知道是否有一种快速方法可以强制删除所有表(因为我将能够重新插入那些我不想删除的).

Of course I could trial and error to see what those key constraints are and eventually delete all tables but I'd like to know if there is a fast way to force drop all tables (as I'll be able to re-insert those I don't want deleted).

Google 将我瞄准了一些建议以下方法的网站:

Google aimed me at some site that suggested the following method:

mysql> SET foreign_key_checks = 0; mysql> drop table ... mysql> SET foreign_key_checks = 1;

简短的回答是它并没有真正起到作用,因为我最终收到了同样的错误,而我能够删除更多的表.我在 Stack Overflow 上看到了将所有外键链接到某个表的方法,但这太耗时了,除非我全部编写脚本(在没有其他选项的情况下这是可行的)

Short answer is it didn't really do the trick since I ended up receiving the same error while I was able to delete some more tables. I've seen on Stack Overflow ways to get all foreign keys linked to a certain table but that's way too time consuming unless I script it all (which is doable in the case there is no other option)

数据库是 4.1,所以我不能使用 DROP DATABASE

Database is 4.1 so I can't use DROP DATABASE

想法?

推荐答案

由于您对保留任何数据不感兴趣,删除整个数据库并创建一个新的.

Since you are not interested in keeping any data, drop the entire database and create a new one.

更多推荐

绕过外键约束强制删除mysql

本文发布于:2023-10-14 21:49:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492313.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:mysql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!