在MySQL中一起更改唯一密钥 [英] Change unique key together in mysql

查看:67
本文介绍了在MySQL中一起更改唯一密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的MYSQL表中有一个唯一键,我想添加到其中.

I have in my MYSQL table a unique key and i want to add to it.

UNIQUE KEY `user_id` (`user_id`,`account_id`)

我想添加另一个

UNIQUE KEY `user_id` (`user_id`,`account_id`,`pet_id`)

推荐答案

ALTER TABLE your_table 
   DROP INDEX user_id, 
   ADD UNIQUE KEY `user_id` (`user_id`,`account_id`,`pet_id`)

注意:如果您在Linux上使用mariadb,则不需要在列名前后加上反引号-实际上,它将引发语法错误1064/(42000)

Note: You won't need the backticks around the column names if you're using mariadb on Linux - in fact it will throw an syntax error 1064/(42000)

这篇关于在MySQL中一起更改唯一密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆