Reputation: 3731
While creating table in mysql I've set wrong name to primary key column.
ALTER TABLE `table_name` CHANGE COLUMN `old_id_name` `new_id_name` integer auto_increment primary key
After that I'm getting
Error message: Multiple primary key defined
So the question is how can I rename the column. Note that I don't want to change primary key to another but just rename it.
Upvotes: 3
Views: 6426
Reputation: 13484
Try this
If your old column already contains NOT NULL
and AUTO_INCREMENT
property just use it
ALTER TABLE tablename CHANGE column old_name new_name int;
or if you need to add NOT NULL
and AUTO_INCREMENT
property use it
ALTER TABLE tablename CHANGE column old_name new_name int NOT NULL AUTO_INCREMENT;
Upvotes: 2
Reputation: 2729
Try this:
ALTER TABLE table_name CHANGE column old_name new_name int;
Upvotes: 2
Reputation: 2584
use query like this
ALTER TABLE `table_name` CHANGE `old_id_name` `new_id_name` INT(11) NOT NULL AUTO_INCREMENT;
it will change only the column name of primary key
Upvotes: 7