Check existence of key before adding it using alter table to avoid error messages?
Posted on 2007-11-23
When I execute the MySQL command
ALTER TABLE `forum_reply`
MODIFY `type` int(11),
ADD KEY `fid` (`fid`);
it generates the error:
Error Code : 1061
Duplicate key name 'fid'
which is obvious because the same key 'fid' already exist. Is there a way to check the existence of a key before executing the ADD KEY `fid` (`fid`) command? Because some of my clients does have key created and some don't depending on the version of a script they are using and this error is really bugging me because of the overwhelming support requests I get.
Or is there a way to just ignore and force creating of a key by overwriting an exist key? Either way will solve the problem for me. Thanks.