Search

Ash Burton

Mobile | Web | Data

Mobile Payments, Android, iOS, Mobile Web, HTML5, Multichannel Customer Service, Web Services, IVR, Business Intelligence, Telecoms, Radio, Photography, Running, Gaming

Change a Column's Data Type in MySQL (equivalent of ALTER COLUMN)

I just thought I'd post this little tip as the syntax difference between MySQL and Microsoft SQL Serverjust foxed me once again...

ALTER TABLE my_table 
CHANGE my_column my_column SMALLINT NOT NULL DEFAULT 0;

You may wonder why the column name is repeated twice, that's because the same syntax also allows you to rename the column at the same time.  The syntax might be a little odd but it does makes sense if you think about it.