MySQL: making a column unique?

StackOverflowNewbie picture StackOverflowNewbie · Jul 4, 2011 · Viewed 58.7k times · Source

I have a table that is in production. I realize that some of the columns should be unique. Is it safe to go into phpMyAdmin and change those columns to make it unique?

ALTER TABLE  `foo` ADD UNIQUE ( `bar` )

Answer

Rahul Mankar picture Rahul Mankar · Jul 13, 2017

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);