简体   繁体   English

Mysql和索引中两列的唯一约束

[英]Unique constraint for two columns in Mysql and indexes

Sorry for newbie question - am I understand right that these two operators are identical in Mysql? 对不起,对于新手问题-我能正确理解Mysql中这两个运算符是相同的吗?

ALTER TABLE friends ADD CONSTRAINT UNIQUE (`user_id`, `friend_id`);

and

CREATE UNIQUE INDEX friends_user_friend ON friends (user_id, friend_id);

yes ! 是的!

only CREATE INDEX cannot be used to create a PRIMARY KEY, use ALTER TABLE instead 仅CREATE INDEX不能用于创建主键,而应使用ALTER TABLE

read more in : 阅读更多内容:

http://dev.mysql.com/doc/refman/5.0/en/create-index.html http://dev.mysql.com/doc/refman/5.0/en/create-index.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM