1

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

2 Answers2

1
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 )
Mihai
  • 26,325
  • 7
  • 66
  • 81
  • You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ALTER IGNORE TABLE mytable ADD UNIQUE (field1,field2 )' at line 1 0.000 sec – Julien Apr 29 '16 at 08:14
1
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

Community
  • 1
  • 1
Julien
  • 2,616
  • 1
  • 30
  • 43