mysql - 在mysql中一起更改唯一键

标签 mysql unique

我的 MYSQL 表中有一个唯一键,我想添加到它。

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`)

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 - 在mysql中一起更改唯一键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20116140/

相关文章:

php - 无法使用不同的方法连接到 mysql

c# - TransactionScope:如果内部范围失败,如何使外部范围继续?

python - 检查并索引 numpy 数组中的非唯一/重复值

c# - 使用 LINQ 获取所有可能的不同三元组

google-sheets - 独特的公式 + 如果

mysql - 分组依据、排序依据无法正常工作 - SQL 模式 - ONLY_FULL_GROUP_BY

mysql - 如何对另一个表中没有匹配条目的行进行求和?

java - 使用 Spring Data JPA 访问数据时,会在任一表上创建空列

c# - 确保列表中的每个项目都是唯一的?

python - 从对象列表中获取唯一的 id 列表