MySQL Rename Column

Profile picture for user arilio666

Sometimes we might need to change the table name, and for this purpose, we can use the ALTER TABLE command to rename an existing table.

Syntax

ALTER TABLE Table_Name RENAME TO New_Table_Name

ALTER TABLE Table_Name RENAME COLUMN Old_Name New_Name

Let us see in the real-time example.

For this, we are going to use the employees table.

MySQL Rename Column

Changing the table name

ALTER TABLE employees RENAME TO Employee_details

mysql Changing the table name

  • We can see that using the first syntax, and the table name has been modified into our required one.

Changing the column name

ALTER TABLE Employee_details RENAME COLUMN job_title TO designation

mysql Changing the column name

  • We can see that the column name has also been modified according to our second syntax.

In this way, we can use this alter table command to rename tables and columns in a database.

Tags