在mysql
中,如何利用ALTER TABLE
语句配合DROP
关键字来删除外键关系(约束)。
基本语句介绍:
ALTER TABLE 数据表名 DROP FOREIGN KEY 外键约束名;
实例一:查看数据表 tb_emp2 的外键约束
SHOW CREATE TABLE tb_emp2\G
mysql> SHOW CREATE TABLE tb_emp2\G
*************************** 1. row ***************************
Table: tb_emp2
Create Table: CREATE TABLE `tb_emp2` (
`id` int(11) NOT NULL,
`name` varchar(30) DEFAULT NULL,
`deptId` int(11) DEFAULT NULL,
`salary` float DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `fk_tb_dept1` (`deptId`),
CONSTRAINT `fk_tb_dept1` FOREIGN KEY (`deptId`) REFERENCES `tb_dept1` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gb2312
1 row in set (0.12 sec)
实例二:删除数据表 tb_emp2 中的外键约束 fk_tb_dept1
ALTER TABLE tb_emp2 DROP FOREIGN KEY fk_tb_dept1;
mysql> ALTER TABLE tb_emp2
-> DROP FOREIGN KEY fk_tb_dept1;
Query OK, 0 rows affected (0.19 sec)
Records: 0 Duplicates: 0 Warnings: 0
以上是编程学习网小编为您介绍的“mysql如何删除外键关系语句介绍”的全面内容,想了解更多关于 mysql 内容,请继续关注编程基础学习网。
织梦狗教程
本文标题为:mysql如何删除外键关系语句介绍


基础教程推荐
猜你喜欢
- k8s部署redis集群搭建过程示例详解 2023-07-13
- MySQL热备份(实时备份)及恢复 2024-01-31
- SQL基础的查询语句 2023-08-06
- python windows安装cuda+cudnn+pytorch教程 2023-07-27
- Redis ZREM命令 2024-02-07
- Python实现从PPT中导出高分辨率图片 2023-07-27
- WINDOWS REDIS 修改requirepass 不生效; 2024-02-14
- Mysql中Table ‘XXX’ is marked as crashed and last (automatic?)问题解决方法 2024-01-11
- postgresql无序uuid性能测试及对数据库的影响 2023-07-21
- MySQL数据库 触发器 trigger 2024-01-09