PHP, MySQL, Drupal, .htaccess, Robots.txt, Phponwebsites: Change column datatype in mysql

29 Dec 2013

Change column datatype in mysql

                       You created a table with column in specific datatype. Sometimes you need to change datatype of column. At the time, you can modify the datatype of field. It is possible in mysql. The following mysql query is used for this:
Mysql Query:
                         Alter table table_name modify column_name datatype(length)

Consider the example:
 table1 is name of this table.

changing column size in mysql at phponwebsites

When you click the structure of table in your database, it is look like this:

Structure of table in mysql

                          Suppose you've to change datatype of column 'Game_name'. On that time you can change the field type. The mysql query is:

                     Alter table table1 modify Game_name char(15)

Now your structure look like this:

change column field in mysql

     Now your Game_name column type is changed from varchar into char.

Changing the multiple column datatype at the time in mysql:

                      You can change multiple column datatype at a time in mysql. The mysql query as follow as:
Mysql Query:
                          Alter table table1
                                    modify No varchar(5),
                                    modify Game_name char(15),
                                    modify Image char(15)

                          Now your output look like this:

change multiple column datatype at a time in mysql

                          Now you will get output column 'No' with varchar, 'Game_name' with char and 'Image' with char in your mysql table.

Datatypes in mysql:

datatypes in mysql

1 comment: