In this example How to change column name in MySQL. First of all we have created MySQL database with many fields in table. We rename a column in MySQL using alter Table name and change. The current column is named old_col but if you want to change the column name to new_col it can be done using the syntax given below.
ALTER TABLE table_name CHANGE old_col new_col data_type:
This query is run to change the specific column name:-
First of all you will create MySQL database
CREATE TABLE `changetableName` ( `id` int(10) NOT NULL, `old_name` varchar(10) DEFAULT NULL, `new_Name` varchar(10) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1
The following image display a table with column name "old_name" and "new_Name". Now we need to change these column name.
To change the column name we use the following command:
alter table changetablename change old_name name varchar (10) ;
alter table changetablename change new_Name address varchar (10) ;
This image displays the changed column name "name"
If you enjoyed this post then why not add us on Google+? Add us to your Circles
Liked it! Share this Tutorial