How to change MySQL column definition?

Mask picture Mask · Oct 20, 2009 · Viewed 262.2k times · Source

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?

Answer

mikej picture mikej · Oct 20, 2009

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);