Unique constraint for two columns in Mysql and indexes

Sorry for the newbie question - did I understand correctly that these two operators are identical in Mysql?

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

      

and

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

      

+2


source to share


1 answer


Yes!

CREATE INDEX alone cannot be used to create a PRIMARY KEY, use ALTER TABLE instead



read more in:

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

+4


source







All Articles