Rename columns in Mysql

To rename a column in MySQL, you can use the ALTER TABLE statement along with the CHANGE keyword. Here's the syntax:

Syntax:
                
    ALTER TABLE table_name CHANGE old_column_name new_column_name column_definition;
                
            

Let's say we have a table called employees with the following structure:

Syntax:
                
    CREATE TABLE employees (
      id INT PRIMARY KEY,
      first_name VARCHAR(50),
      last_name VARCHAR(50),
      salary DECIMAL(10,2)
    );
                
            

And we want to rename the column last_name to surname. Here's how you can do it:

Syntax:
                
    ALTER TABLE employees CHANGE last_name surname VARCHAR(50);
                
            

After executing the above statement, the column last_name will be renamed to surname with the same data type and length.

Remember to replace table_name with the actual name of your table and old_column_name and new_column_name with the appropriate column names in your scenario. Also, provide the appropriate column definition (data type and length) for the new column name

It's important to note that renaming a column may affect other parts of your application that rely on the old column name, such as queries or code referencing that column. So make sure to update your queries and code accordingly after renaming a column.