问题
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