MySQL 在mysql中一起更改唯一键
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20116140/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change unique key together in mysql
提问by yossi
I have in my MYSQL table a unique key and i want to add to it.
我的 MYSQL 表中有一个唯一键,我想添加到它。
UNIQUE KEY `user_id` (`user_id`,`account_id`)
and i want to add another
我想添加另一个
UNIQUE KEY `user_id` (`user_id`,`account_id`,`pet_id`)
回答by juergen d
ALTER TABLE your_table
DROP INDEX user_id,
ADD UNIQUE KEY `user_id` (`user_id`,`account_id`,`pet_id`)
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)
注意:如果您在 Linux 上使用 mariadb,则不需要列名周围的反引号 - 实际上它会抛出语法错误 1064/(42000)
回答by Jakob
Drop the first key and then create the new one.
删除第一个键,然后创建新键。