How To Rename a Column using SQL?

Date Published: 23/08/2020 Published By: JaiSchool

This is a very simple process. For example, I have a table mobiles and this table contains a column brand. Now, I want to change the name of the column from brand to brand_name.

Then, Run following command to rename the column-

ALTER TABLE mobiles CHANGE brand brand_name VARCHAR(30);

Do not try to change its data type like INT to VARCHAR or VARCHAR to INT, It may throw errors. As if brand column's fields have string data in it and you are trying to change it to INT. Then you will not be able to do that.

It is only possible when the table is empty or the column fields are empty which you are trying to convert into another data type.

Publish A Comment

Leave a Reply

Your email address will not be published. Required fields are marked *