Link to home
Start Free TrialLog in
Avatar of bhomass
bhomass

asked on

add unique constraint to an existing table

I have an existing table, webcommand. I want to add an uniqueness constraint to the commandname column.

I tried alter table webcommand add constraint unqiue 'commandname'. but it fails with a syntax error.

please tell me the right syntax.
ASKER CERTIFIED SOLUTION
Avatar of dqmq
dqmq
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Steve Bink
You can also use a unique index.  I believe they are functionally equivalent in MySQL if you are not using foreign keys.

http://dev.mysql.com/doc/refman/5.1/en/create-index.html

CREATE UNIQUE INDEX ui_commandname ON webcommand (commandname)
Avatar of bhomass
bhomass

ASKER

unique key is the one I was looking for.

maybe the unique index is a good way too. but sorry I don't know anything about it.