删除唯一性约束unique

时间:2021-12-06 22:30:06

删除唯一性约束

语法如下:

alter table tableName drop index key_name;#删除唯一性约束,实际就是删除索引

drop index key_name on tableName; #两种方法均可

mysql> show create table t_user;
+--------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+--------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t_user | CREATE TABLE `t_user` (
`id` int(10) DEFAULT NULL,
`name` varchar(32) NOT NULL,
`email` varchar(128) DEFAULT NULL,
UNIQUE KEY `name` (`name`,`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+--------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> alter table t_user drop index name;
mysql> show create table t_user;
+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t_user | CREATE TABLE `t_user` (
`id` int(10) DEFAULT NULL,
`name` varchar(32) NOT NULL,
`email` varchar(128) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+--------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)