How to change Column size of varchar type in mySQL?

MysqlSql

Mysql Problem Overview


I have the following table emp :

Field 	Type 	   Null 	Key 	Default 	Extra 	
id 	    int(11)	    NO 	    PRI 	NULL	auto_increment
name 	varchar(20)	YES 		    NULL	
dept 	varchar(20)	YES 		    NULL	

Now I like to change the varchar size of name from 20 to 50.

I have tried with the following SQL queries but the same error shows :

ALTER TABLE emp
CHANGE COLUMN 'name' varchar(100);


ALTER TABLE emp
ALTER  COLUMN name varchar(100);

This is the ERROR :

>1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(100)' at line 2

Any idea how to change the column size of varchar type in MYSQL ?

Mysql Solutions


Solution 1 - Mysql

ALTER TABLE emp MODIFY COLUMN name VARCHAR(100);

Or use CHANGE, but that means you have to give the column name twice (because CHANGE allows you to change the name of the column too).

ALTER TABLE emp CHANGE COLUMN name name VARCHAR(100);

Don't put the column name in single-quotes. Single-quotes are for string literals or date literals.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionZahid RoufView Question on Stackoverflow
Solution 1 - MysqlBill KarwinView Answer on Stackoverflow