rishabh gupta
rishabh gupta

Reputation: 11

How to change the type of a particular row/cell from int to varchar

I have created a table in mysql. In the table I defined earlier a type int for "Phone number" but it's throwing an error while entering the phone number that: "ERROR 1265 (01000): Data truncated for column 'phone' at row 1".

So I tried to change the type of the field Phone from 'int' to 'varchar' but I am not able to change.

I know we can use ALTER command like I tried - "ALTER TABLE student(table name) COLUMN MODIFY varchar"

However, it is modifying the type of whole column while I just want to change the type of a particular cell/row.

Upvotes: 1

Views: 308

Answers (2)

Faiz Ahmed
Faiz Ahmed

Reputation: 415

Use this commands.

USE dbname;
ALTER TABLE table1 CHANGE phonenumber phonenumber varchar(255);

or 

USE dbname;
ALTER TABLE table1 MODIFY phonenumber1 varchar(25);

Upvotes: 1

user8406805
user8406805

Reputation:

You can use the below SQL ALTER statement to modify your column type as:

alter table cell_info modify nums varchar(20);

Example: create table cell_info(id int, nums int); insert into cell_info values(1,12341234); alter table cell_info modify nums varchar(20); insert into cell_info values(1,'My new number');

select * from cell_info;

DEMO

Upvotes: 0

Related Questions