PHP, MySQL, Drupal, .htaccess, Robots.txt, Phponwebsites: change
change - phponwebsites.com
Showing posts with label change. Show all posts

19 Jan 2014

Change column with NOT NULL to NULL in mysql

                       You created a table in which the column with 'NOT NULL'. Suppose you want to change mysql column definition from 'NOT NULL' to 'NULL'. Then how can you change it in mysql. The following mysql query is used to change column from 'NOT NULL' to 'NULL' in mysql.
Mysql Query:
                         Alter table table_name 
                            change column_name column_name datatype(length) definition


Change column NOT NULL to NULL in mysql:


Consider the example:
The structure of table1 in database new look like this:


change column definition in mysql

       
                Where, the column name 'No' is NOT NULL. You can see the Null column value is No in above mysql table at first row.  Now we are going to change column 'NOT NULL' to 'NULL' in mysql table 'table1'.  The mysql query is:
                 
                           Alter table table1 change No No int(5) NULL

Now your structure look like this:


change column NOT NULL to NULL in mysql


                            Now you can see the column name 'No' is NULL.


Change column NULL to NOT NULL in mysql:


                                         Similarly you can change the column definition from NULL to NOT NULL. The mysql query as follows as:

                                            Alter table table1 change No No int(5) NOT NULL

                        Now the column 'No' changed NULL to NOT NULL.

Related Post:

27 Dec 2013

Move columns in mysql table

                       You can change the column name and change the column size in mysql. But can you rearrange the column order in mysql table. Yes, you can rearrange it in mysql. It can be done by 'ALTER', 'CHANGE' and 'AFTER' mysql command. The mysql query for move the column in mysql table is:

                   " ALTER TABLE table_name CHANGE column_name column_name datatype(length) AFTER column_name"

                       You can also done by 'MODIFY' mysql command. The mysql query as follows as:

                   " ALTER TABLE table_name MODIFY column_name datatype(length) AFTER column_name"

Consider the following example: table1 is the name of table.
                   
rearrange columns in mysql

                       Now the column 'name' is moved after column 'img'. The mysql query as follows as:

                   " ALTER TABLE table1 CHANGE name name varchar(30) AFTER img"

Now you'll get output like this:

move column using MODIFY mysql command

The column name 'name' is placed after 'img' in mysql table 'table1'.


Move  multiple columns at the time in mysql:


                             You can move multiple columns at the time in mysql. The column name order id, name ,img in table1 is changed into img, name ,id. The mysql query as follows as:

                         "ALTER TABLE table1 CHANGE id id int(5) AFTER img,
                                         CHANGE name name varchar(30) AFTER img"

Now you'll get output like this:

move multiple columns at a time in mysql using CHANGE command

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: