Is it possible to drop all foreign key constraints on a table at once in mySQL 5?(是否可以在 mySQL 5 中一次删除表上的所有外键约束?)
问题描述
在 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.
这篇关于是否可以在 mySQL 5 中一次删除表上的所有外键约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否可以在 mySQL 5 中一次删除表上的所有外键约束?


基础教程推荐
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01