change column definition in existing table

1.6k views Asked by At

I need to edit a datatype (IS_NULLABLE) from my column tag. Nothing works, i have tried like that:

ALTER TABLE veille
ALTER COLUMN tag
SET IS_NULLABLE false

or like that :

ALTER TABLE veille ALTER COLUMN tag Modify datatype false

but doesn't work too, i have this error :

 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 'IS_NULLABLE false' at line 3. 

Edit : Resolved, the problem was my column has null values, i have changed these null values and all works fine.

3

There are 3 answers

26
Stephen On

try ALTER TABLE veille_ndd_hist MODIFY tag bit(1) NOT NULL DEFAULT b'0;

you may also try ALTER TABLE veille_ndd_hist CHANGE COLUMN tag tag BIT NOT NULL

Note that when using MODIFY, you need to specify the full column definition, including DEFAULT value if was defined.

side note: of course make sure that the column does not have any null values

0
VahiD On

use

ALTER TABLE veille ALTER COLUMN tag datatype

columns are nullable by default, As long as the column is not declared UNIQUE or NOT NULL, there shouldn't be any problems.

refer to this question: How do I modify a MySQL column to allow NULL?

1
jophab On

No need for datatype false Just use the query like below

alter table table_name modify column tag <datatype> not null;