Home Sql Mysql-alter Mysql Alter Data Type



Mysql Alter Data Type
Posted on: January 13, 2009 at 12:00 AM
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 | | | |

Related Tags for Mysql Alter Data Type:
sqlmysqlctabledatedatasedtypecolumnchangetabiftodatatypemodifyealterhangusepeinmodmaltmodiumnscolatmyishassthababllumolo


More Tutorials from this section

Ask Questions?    Discuss: Mysql Alter Data Type  

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.