3

I want to rename "InputOutputConfigurationServerAccountId" to "CompositeKey". How do I do this via SQL?

Part of my table definition:

UNIQUE KEY `InputOutputConfigurationServerAccountId` (`InputOutputConfigurationServerAccountId`,`Identifier`,`TimeStampReceived`)

The table is already in production. I am trying to alter the table.

StackOverflowNewbie
  • 39,403
  • 111
  • 277
  • 441

2 Answers2

7

Yep Femi is right. it would be done like this:

ALTER TABLE `test`.`UniqueKeys` 

DROP INDEX `InputOutputConfigurationServerAccountId`, 
ADD UNIQUE INDEX `CompositeKey` (`InputOutputConfigurationServerAccountId`,
`Identifier`,`TimeStampReceived`) ;
jmruc
  • 5,714
  • 3
  • 22
  • 41
Edgar Velasquez Lim
  • 2,426
  • 18
  • 15
1

There is currently no support in MySQL's ALTER syntax to rename a key. You will have to create a new composite key and drop the old one.

Femi
  • 64,273
  • 8
  • 118
  • 148