I am trying to rename a column in MySQL community server 5.5.27 using this SQL expression:
ALTER TABLE table_name RENAME COLUMN old_col_name TO new_col_name;
I also tried
ALTER TABLE table_name RENAME old_col_name TO new_col_name;
But it says:
Error: check the Manual that corresponds to your MySQL server version
The syntax to modify a column in a table in MySQL (using the ALTER TABLE statement) is: ALTER TABLE table_name MODIFY column_name column_definition [ FIRST | AFTER column_name ]; table_name. The name of the table to modify.
You can rename a column with the below code. You select the table with ALTER TABLE table_name and then write which column to rename and what to rename it to with RENAME COLUMN old_name TO new_name .
Using MariaDB alter table to rename a column in a table. In this syntax: First, specify the name of the table from which you want to rename the column after the alter table keywords. Second, specify the name of the column and the new name followed by the column definition after the change column keywords.
Use the following query:
ALTER TABLE tableName CHANGE oldcolname newcolname datatype(length);
The RENAME
function is used in Oracle databases.
ALTER TABLE tableName RENAME COLUMN oldcolname TO newcolname datatype(length);
@lad2025 mentions it below, but I thought it'd be nice to add what he said. Thank you @lad2025!
You can use the RENAME COLUMN
in MySQL 8.0 to rename any column you need renamed.
ALTER TABLE table_name RENAME COLUMN old_col_name TO new_col_name;
ALTER TABLE Syntax: RENAME COLUMN:
- Can change a column name but not its definition.
- More convenient than CHANGE to rename a column without changing its definition.
In Server version: 5.6.34 MySQL Community Server
ALTER TABLE table_name CHANGE COLUMN old_column_name new_column_name data_type;
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