How to make a field unique in existing database table

In order to make a field unique in your existing table you can either run a sql statement or use a visual sql client like HeideSQL.

This is an example on how to make your emp_id field unique in your existing employee table.


ALTER TABLE `employee` ADD UNIQUE INDEX `emp_id` (`emp_id`);

  1. This is the return error for duplicate entry

    SQL Error (1062): Duplicate entry ‘ID007′ for key ‘emp_id’

  2. Nice info..Thanks

Leave a Comment