是否可以在 mySQL 5 中一次删除表上的所有外键约束?

2022-01-20 00:00:00 foreign-keys mysql

在 mySQL 5 中,有没有一种方法可以用一条 SQL 语句删除表上的所有外键约束,而不用名称来引用它们?

In mySQL 5, is there a way to drop all foreign key constraints on a table with one SQL statement without referring to them by name?

我正在编写一个数据库更新脚本,不幸的是,有些网站的限制是用错误"的名称创建的.我试图避免进入并从数据库中获取实际的约束名称并将它们插入回 SQL 语句中.

I'm writing a DB update script, and unfortunately some of the sites had constraints created with "wrong" names. I'm trying to avoid going in and getting the actual constraint names from the DB and inserting them back into SQL statements.

推荐答案

您当然可以选择 * 表到临时表,删除并重新创建它,然后复制回来.

You can surely select * the table to a temp table, drop and recreate it, then copy back.

相关文章