Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a column of type TEXT to VARCHAR?

Tags:

mysql

Is there a way to convert a column with data in it as TEXT to VARCHAR(X) easily? There are no existing records in the column is longer than X.

like image 607
user1768076 Avatar asked Nov 23 '12 14:11

user1768076


People also ask

How do I cast TEXT to VARCHAR in SQL Server?

The CAST() function converts a value (of any type) into a specified datatype.

Can VARCHAR store TEXT?

You can also use VARCHAR to store short strings—VARCHAR(40), for example—but it can store any string up to the maximum column size, using a variable amount of storage space. Next, TEXT and its variants. Text is based on the BLOB (binary large object) type.


2 Answers

Yes for sure

ALTER TABLE table_name MODIFY column_name VARCHAR(X)

like image 113
Shakti Singh Avatar answered Oct 02 '22 05:10

Shakti Singh


For MS SQL:

ALTER TABLE table_name ALTER COLUMN column_name datatype(value) 

For MySQL

ALTER TABLE table_name MODIFY column_name datatype(value) 
like image 44
Hello World Avatar answered Oct 02 '22 05:10

Hello World