How do I rename a primary key column in MySQL?
Show activity on this post. drop foreign keys from others tables pointing to the primary key you want to rename. rename the primary key. add the foreign column to other tables.
Rename MySQL Column with the CHANGE Statement Enter the following command in your MySQL client shell to change the name of the column and its definition: ALTER TABLE table_name CHANGE old_column_name new_col_name Data Type; You can change the data type of the column or keep the existing one.
In SQL Server, you can use the sp_rename stored procedure to rename a user created object in the current database, including a primary key. This can be handy if you've got a primary key that had its name automatically assigned, and you now want to give it a more readable name.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With