

ALTER TABLE StudentsĬHANGE COLUMN firstname first_name varchar(50),ĬHANGE COLUMN surname last_name varchar(50) įinally, if we do DESCRIBE TABLE on Students then we can see the changes.Learn how to safely rename a column in a MySQL database using a universal multi-featured tool – dbForge Studio for MySQL. In this example, we will change the name of the first_name column to firstname, last_name to surname, and the datatype of both the column to varchar(100). Now we will check how to rename multiple columns in a single statement using the CHANGE keyword. ALTER TABLE StudentsĪs you can see from the above image that the column name id changed to roll_no and its datatype to varchar(10). You can use the following statement for the same. Now we want to change the column name id to roll_no and its datatype to varchar(10) from int. Suppose, we have a Students table as below. Let us understand the concept of changing column names using the CHANGE statement with the help of some examples. The syntax for the same is as below: ALTER TABLE table_nameĬHANGE COLUMN old_column_name1 new_column_name1 Data Type,ĬHANGE COLUMN old_column_name2 new_column_name2 Data Type, You can also rename multiple columns in a single statement.

You can use the following syntax to change the name of the column using the CHANGE COLUMN statement. You can also use the CHANGE COLUMN command to rename a column in MySQL. MySQL RENAME COLUMN using CHANGE statement

ALTER TABLE StudentsĪfter successful completion of the above statement, let’s check the table using the SELECT statement.įrom the above output, you can notice that the name of the student_age column changed to age and the name of the student_email column changed to only email. In the below example, we will change the column name student_age to age and student_email to email. Now, let us take an example of changing multiple columns in a single statement. ALTER TABLE StudentsĪs you can see from the above image that the name of the roll_no has been changed to the id successfully. We can do this using the following statement. Suppose, we want to change the name of the column roll_no to id without changing the datatype. Suppose, we have a Students table with the following data. Let’s understand the concept of renaming columns with the help of a few examples. Here, you need to specify each RENAME COLUMN statement separated by comma( ,). RENAME COLUMN old_column_name2 TO new_column_name2, RENAME COLUMN old_column_name1 TO new_column_name1, Below is the syntax: ALTER TABLE table_name You can also change the name of multiple columns in a single statement. Second, specify the name of the old column name after the RENAME COLUMN keywords.Īnd Finally, provide the new column name after the TO keyword. RENAME COLUMN old_column_name TO new_column_name įirst, specify the name of the table whose column you are going to rename after the ALTER TABLE keywords. This is the commonly used command to change a column name.īelow is the basic syntax of renaming a column in MySQL. MySQL RENAME COLUMN using RENAME statement You can rename a column name in MySQL in two ways: This command is used along with the ALTER TABLE statement. MySQL RENAME COLUMN is used to change the column name of a MySQL table. MySQL allows us to modify its objects using just a few commands. Sometimes we may need to change a column name of a MySQL table. Summary: in this tutorial, you will learn how to rename a column of a table using MySQL RENAME COLUMN and CHANGE COLUMN statements with examples.
