如何在 mySQL 中添加多列唯一键

How to add multiple column Unique key in mySQL

我想添加我正在使用以下查询的唯一约束,但它给我一个 SQL 语法错误

改变TABLE user_device 添加约束UKnfrn6f2pu3tqcwhqen0d6cq7u (owner,push_notification_id);

哪里错了:| 它突出显示了 push_notification_id

中的错误

这样做。

ALTER TABLE user_device ADD unique index UKnfrn6f2pu3tqcwhqen0d6cq7u (owner,push_notification_id);
ALTER TABLE user_device ADD CONSTRAINT UKnfrn6f2pu3tqcwhqen0d6cq7u UNIQUE KEY  (owner,push_notification_id);

试试上面的代码。 您没有提到要在该列组合上创建哪种类型的键。 所以我提到过使用 UNIQUE KEY 关键字。

希望对您有所帮助。