强制删除mysql绕过外键约束

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

我试图从数据库中删除除了一个以外的所有表,并且最终出现以下错误: lockquote

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

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

Google在一些网站上向我推荐了以下方法:

mysql> SET foreign_key_checks = 0; mysql>删除表... mysql> SET foreign_key_checks = 1;简单的答案是它没有真正的伎俩,因为我最终收到同样的错误,而我能够删除更多的表格。我已经看到堆栈溢出的方式来获取所有的外键链接到某个表,但是这太耗费时间,除非我编写脚本(这是可行的,在没有其他选择的情况下)

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

因为你不想保留任何数据,所以 解决方案

refman / 5.0 / en / drop-database.htmlrel =nofollow noreferrer>删除整个数据库并创建一个新的。

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 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;

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)

Database is 4.1 so I can't use DROP DATABASE

Ideas?

解决方案

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

更多推荐

强制删除mysql绕过外键约束

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

发布评论

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

>www.elefans.com

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