How to change MySQL column definition?

MysqlAlter Table

Mysql Problem Overview


I have a mySQL table called test:

create table test(
    locationExpect varchar(120) NOT NULL;
);

I want to change the locationExpect column to:

create table test(
    locationExpect varchar(120);
);

How can it be done quickly?

Mysql Solutions


Solution 1 - Mysql

Do you mean altering the table after it has been created? If so you need to use alter table, in particular:

ALTER TABLE tablename MODIFY COLUMN new-column-definition

e.g.

ALTER TABLE test MODIFY COLUMN locationExpect VARCHAR(120);

Solution 2 - Mysql

Syntax to change column name in MySql:

alter table table_name change old_column_name new_column_name data_type(size);

Example:

alter table test change LowSal Low_Sal integer(4);

Solution 3 - Mysql

This should do it:

ALTER TABLE test MODIFY locationExpert VARCHAR(120) 

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
QuestionMaskView Question on Stackoverflow
Solution 1 - MysqlmikejView Answer on Stackoverflow
Solution 2 - MysqlNiranjan VaddiView Answer on Stackoverflow
Solution 3 - MysqlDaniel RikowskiView Answer on Stackoverflow