Home Jdbc Jdbc-mysql Change Column Name in MySQL
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Change Column Name in MySQL

Advertisement
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.

Change Column Name in MySQL

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.

Syntax:-

ALTER TABLE table_name CHANGE old_col new_col data_type:

This query is run to change the specific column name:-

  • table_name: This is a name of the table in which we have to change the column name.
  • old_col: The old column name that you want to change.
  • new_col: The new column name
  • data_type: This is a data type of new column.

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"

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 18, 2013

Ask Questions?    Discuss: Change Column Name in MySQL  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com