Brian Bruman
Brian Bruman

Reputation: 913

Renaming a Unique Key Name MySQL

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

Answers (3)

Joynal Abedin
Joynal Abedin

Reputation: 75

Find Indexes list from phpmyadmin and drop your unique index.

enter image description here

Upvotes: 0

Robby Cornelissen
Robby Cornelissen

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 same ALTER 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 be PRIMARY.

ALTER TABLE my_table RENAME INDEX ExtendedOrderID TO OrderLineItemID;

Upvotes: 6

Jorge Campos
Jorge Campos

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

Related Questions