How do I rename a primary key column in MySQL? How do I rename a primary key column in MySQL? mysql mysql

How do I rename a primary key column in MySQL?


it's no different than altering any other column --

ALTER TABLE `pkey` CHANGE `keyfield` `keyfield2` INT( 11 ) NOT NULL AUTO_INCREMENT 

this changes the column keyfield in table pkey to be called keyfield2 -- you have to supply the definition afterwards, as usual.


Leave off the PRIMARY KEY part of the alter statement. The primary key will be updated automatically.


Maybe you have a foreign key constraint in place. You can disable those by SET foreign_key_constraints=0 but you have to remember to update the database afterwards.