MySQL: making a column unique?

Follow the below steps to apply unique column value from phpmyadmin panel:

Go to the table structure. Click on the unique keyword as like below -

enter image description here

Click on the ok from confirmation box -

enter image description here

Unique value constraint for column will apply. Or you can run mysql query:

ALTER TABLE user ADD UNIQUE(email);


It will only be a problem if the pre-existing values on the table are not unique, otherwise I don't think there will be any problem.


  1. You do not have duplicates -> will apply the key without issues
  2. You do have duplicates -> will give an error message, nothing happened to your data
  3. All is unique, except several rows with NULL in them, unique constraint is still applied, as NULL is not checked when checking for unique values (you can have the entire table have a NULL value in a unique field without any error message).

One more thing, if you have a prod DB, you must also have a dev DB which you can test on without fear, right?


If there are already some duplicate values in those columns, then this will generate an error. If there aren't any duplicate values in those columns, then you will be fine.