MySQL: how to solve a syntax error in an ALTER TABLE statement while changing a column type

At startup

ALTER TABLE my_table modify column my_column int(10) NOT NULL DEFAULT 0; 

I have an error message:

 Error: 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 'int(10) NOT NULL DEFAULT 0' at line 1. 

How can I fix this problem?

+4
source share
2 answers

Try this code

 ALTER TABLE my_table CHANGE mycolumn my_column INT( 10 ) NOT NULL DEFAULT '1'; 
0
source

ALTER TABLE ... MODIFY COLUMN ... does not allow renaming a column; therefore, the column name should only be provided once (current name).

To rename a column (among other changes that you can use for it, for example, to change its type), you must use ALTER TABLE ... CHANGE COLUMN ... and provide the current and new column names.

See the ALTER TABLE documentation page for more information and examples.

+1
source

All Articles