PHP, MySQL, Drupal, .htaccess, Robots.txt, Phponwebsites: Changing column name in mysql table

22 Dec 2013

Changing column name in mysql table

                       You created a table with specific column name. Sometimes you need to change the column name. At the time, you can change the field name. It is possible in mysql using by CHANGE mysql command. The following mysql query is used for this:
Mysql Query:
                         Alter table table_name change old_column_name  new_column_name datatype(length)


Consider the example:
 table1 is name of this table.

changing column name in mysql at phponwebsites


                          Suppose you've to change the column name. The mysql query is:
                     Alter table table1 change Game_name  name varchar(40)

Now your table look like this:

change column name using CHANGE mysql command

     Now the column name 'Game_name' is changed into 'name'.


Changing the multiple column name at the time in mysql:


                      You can change multiple column name at a time in mysql. The mysql query as follow as:
Mysql Query:
                          Alter table table1
                                    change No id int(5),
                                    modify Image img varchar(40)

                          Now your output look like this:

change multiple column name at the time in mysql at phponwebsites

                          Now you will get output as No to id and Image to img.

Related Post:

No comments:

Post a Comment