Change unique key together in mysql

杀马特。学长 韩版系。学妹 提交于 2019-12-20 10:43:05

问题


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

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

and i want to add another

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

回答1:


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)




回答2:


Drop the first key and then create the new one.



来源:https://stackoverflow.com/questions/20116140/change-unique-key-together-in-mysql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!