Unique Fields in MySQL database

They have: 141 posts

Joined: Aug 1999

Is there a way to change a field to unique using an ALTER TABLE? Right now the only way to make something unique making it the primary key.

Thanks in advance

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

I *think* this will do it:
ALTER table_name ADD UNIQUE field_name

You can read about the mySQL ALTER TABLE syntax here

They have: 10 posts

Joined: Oct 1999

Yeah, it's just like assigning a primary key, must have missed it the first time though.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.