Mysql Alter Data Type

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

Mysql Alter Data Type

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 | [email protected] | 12345 |
| 2 | sourabh | Sourabh | [email protected] | 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 | | | |