Home Sql Mysql-alter Mysql Alter Data Type

Related Tutorials


 
 

Share on Google+Share on Google+

Mysql Alter Data Type

Advertisement
Mysql Alter Date Type is used to modify or change the Column datatype in a table.

Mysql Alter Data Type

     

Mysql  Alter Date Type is used to modify or change the Column datatype in a table.

Understand with Example

The Tutorial cover an example on 'Mysql Alter Date Type'.To understand this example we create a table 'userform' with required fieldname and datatype respectively.The table 'userform' has a  ID as Primary Key.

Create a 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, 
`contact` bigint(20) default NULL, 
PRIMARY KEY (`ID`) 

Describe userform:

The Describe userform is used to describe the table  field,Null,Key,Default etc.

Describe userform;

 

+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| ID | int(11) | NO | PRI | | auto_increment |
| username | varchar(100) | YES | | | |
| fname | varchar(100) | YES | | | |
| email | varchar(100) | YES | | | |
| contact | bigint(20) | YES | | | |

Select the record from table "userform":

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

Query to Alter Table "userform":

The Query  Alter is used to modify the Table "userform" and change the  column datatype from "contact( bigint)" to contact(varchar(130). 

alter table userform change contact contact varchar(130);

 

+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| ID | int(11) | NO | PRI | | auto_increment |
| username | varchar(100) | YES | | | |
| fname | varchar(100) | YES | | | |
| email | varchar(100) | YES | | | |
| contact | varchar(130) | YES | | | |
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  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.

Posted on: January 13, 2009

Related Tutorials

Discuss: Mysql Alter Data Type  

Post your Comment


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