field change into unique? MySQL

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
wvoyance
Forum Contributor
Posts: 135
Joined: Tue Apr 17, 2012 8:24 pm

field change into unique? MySQL

Post by wvoyance »

My database MySQL already had some data inside.
I would like to change one field into unique field.
May I? and, how? Thanks.
x_mutatis_mutandis_x
Forum Contributor
Posts: 160
Joined: Tue Apr 17, 2012 12:57 pm

Re: field change into unique? MySQL

Post by x_mutatis_mutandis_x »

First make sure the data in your column is unique. Assuming it is unique, then you can use the ALTER TABLE syntax:

Code: Select all

ALTER TABLE table_name ADD CONSTRAINT constraint_name UNIQUE (column_name)
Post Reply