Reputation: 93
I want to set as unique a couple of fields in mysql
ex: field1 = 10 field2 = 30
I don't want duplicate for this couple of values. How do I set this in phpmyadmin?
thanks
Upvotes: 1
Views: 3128
Reputation: 2756
ALTER TABLE mytable ADD UNIQUE my_unique_index(field1,field2);
Explanation:
As of MySQL 5.7.4, the IGNORE clause for ALTER TABLE is removed and its use produces an error.
Source : http://dev.mysql.com/doc/refman/5.7/en/alter-table.html
A UNIQUE constraint contains an index definition
Source : MySQL: UNIQUE constraint without index
Upvotes: 1
Reputation: 26784
ALTER IGNORE TABLE mytable
ADD UNIQUE (field1 );
ALTER IGNORE TABLE mytable
ADD UNIQUE (field2 );
Or if you want a combined unique index:
ALTER IGNORE TABLE mytable
ADD UNIQUE (field1,field2 )
Upvotes: 1