Link to home
Start Free TrialLog in
Avatar of 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.
Avatar of dqmq
Flag of United States of America image

Link to home
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.

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


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.