Share on Google+Share on Google+

Mysql Alter Column Default

Ads
Mysql Alter Column Default is used to modify the table and add a default column to Null.

Mysql Alter Column Default

     

Mysql Alter Column Default is used to modify the table and add a default column to Null.

Understand with Example

The Tutorial illustrate an example from 'Mysql Alter Column Default'. To understand and grasp this example we create a table 'userform' with required fieldnames and datatypes respectively.The table 'userform' has a primary key ID column.

Create table "userform":

CREATE TABLE `userform` ( 
`ID` int(11) NOT NULL auto_increment, 
`username` varchar(100) default NULL, 
`fname` varchar(100) default NULL, 
`email` varchar(100) default NULL, 
`count` bigint(20) default NULL, 
PRIMARY KEY (`ID`) 

 

+----+----------+---------+----------------------+-------+
| ID | username | fname | email | count |
+----+----------+---------+----------------------+-------+
| 1 | vineet | vineet | vineet@roseindia.net | 0 |
| 2 | sourabh | Sourabh | srbh@roseindia.net | 0 |
+----+----------+---------+----------------------+-------+

Alter the table 'userform' and add column to set default:

The Query Alter is used to modify table 'usertable' and add the column default value to Null.

ALTER table usertable Modify last_name varchar(50) null;

Describe userform:

The Describe table is used to show the table  fieldname, Type, Null, Key, Default etc.

Describe usertable;

Output

+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| username | varchar(50) | NO | | | |
| first_name | varchar(200) | NO | | | |
| last_name | varchar(50) | YES | | | |
+------------+--------------+------+-----+---------+-------+

Advertisements

Ads

Posted on: January 16, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

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.

Discuss: Mysql Alter Column Default  

Post your Comment


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

Ads

Advertisement