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.

Ads

Tutorials   
Change Column Name in MySQL Java Mysql Connection Example JDBC Example with MySQL Jdbc Mysql Connection String Jdbc Mysql Connection Url Getting Column Names from a database table in Java Count Rows from a Database Table JDBC Example with MySQL Write Text File to Table Inserting Image in Database Table Insert Data in Table Using Stored Procedure Copy One Database Table to Another Copy Table in a MySQL Database Set Timestamp by using the Prepared Statement Set Time by using the Prepared Statement Set Date by using the Prepared Statement Prepared Statement Set Big Decimal Set byte, short and long data types by using the Prepared Statement Set Data Types by using Prepared Statement Using the Prepared Statement Twice Deleting Records using the Prepared Statement Count Records using the Prepared Statement Inserting Records using the Prepared Statement Update Records using Prepared Statement Select Records Using Prepared Statement Prepared Statement With Batch Update Statement Batch Update Prepared Statement Set Object Cross Join Tables in a Specific Database Join tables with the NATURAL RIGHT JOIN operation Join tables with the NATURAL LEFT JOIN operation Join tables in the specific database Delete a Column from a Database Table Delete a Specific Row from a Database Table Deleting All Rows from a Database Table Sum of Column in a Database Table Arrange a Column of Database Table Arrange a Column of Database Table Remove Unique Column in Database Table Make Unique Column in Database Table

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"

Advertisements

Ads
Share on Google+Share on Google+

Change Column Name in MySQL

Posted on: July 18, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Change Column Name in MySQL  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads