I am trying to rename a column in MySQL community server 5.5.27 using this SQL expression:
ALTER TABLE table_name R
In Server version: 5.6.34 MySQL Community Server
ALTER TABLE table_name
CHANGE COLUMN old_column_name new_column_name data_type;
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);
Notice the backticks used for MySQL, whereas double quotes are used for Oracle's syntax. Also note that MySQL 8.0 might not accept backticks. In that case, execute the query without backticks and it will probably work.
@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.
https://dev.mysql.com/doc/refman/8.0/en/alter-table.html
For MySQL 8
alter table creditReportXml_temp change column applicationID applicantID int(11);
You can use following code:
ALTER TABLE `dbName`.`tableName` CHANGE COLUMN `old_columnName` `new_columnName` VARCHAR(45) NULL DEFAULT NULL ;
Syntax: ALTER TABLE table_name CHANGE old_column_name new_column_name datatype;
If table name is Student and column name is Name. Then, if you want to change Name to First_Name
ALTER TABLE Student CHANGE Name First_Name varchar(20);
In mysql your query should be like
ALTER TABLE table_name change column_1 column_2 Data_Type;
you have written the query in Oracle.