Reputation: 913
I had a column that had a UNIQUE KEY
ExtendedOrderID
.
I renamed this column to OrderLineItemID
.
Still, when I go to SHOW CREATE TABLE
it is stating
. . .
UNIQUE KEY `ExtendedOrderID` (`OrderLineItemID`)
. . . ) ENGINE=InnoDB . . .
Showing my original column name.
Now, I don't think this is affecting anything, since it's still pointing to the new properly named column OrderLineItemID
, but how do I completely remove ExtendedOrderID
from the table and rename it to show properly
UNIQUE KEY `OrderLineItemID` (`OrderLineItemID`)
Upvotes: 3
Views: 5572
Reputation: 97150
You can rename it using the RENAME INDEX
clause in the ALTER TABLE
command (since MySQL 5.7).
From the documentation:
RENAME INDEX old_index_name TO new_index_name
renames an index. This is a MySQL extension to standard SQL. The content of the table remains unchanged.old_index_name
must be the name of an existing index in the table that is not dropped by the sameALTER TABLE
statement.new_index_name
is the new index name, which cannot duplicate the name of an index in the resulting table after changes have been applied. Neither index name can bePRIMARY
.
ALTER TABLE my_table RENAME INDEX ExtendedOrderID TO OrderLineItemID;
Upvotes: 6
Reputation: 23361
You have to drop it and then recreate it again with the new name:
alter table yourTableName drop index ExtendedOrderID;
create unique index OrderLineItemID on yourTableName (OrderLineItemID);
Upvotes: 3