26
votes

An existing MySQL table has a DateTime field which is not null and having a Default Value set as '0001-00-00 00:00:00'. Is it possible to Alter this table to remove the default value for the DateTime field ?

2

2 Answers

44
votes

Yes, you can drop the default using an ALTER TABLE statement like this:

alter table your_table 
  alter column your_column drop default;
6
votes

To drop the default from multiple datetime columns in a table:

ALTER TABLE your_table 
   ALTER COLUMN columnname1 DROP DEFAULT,
   ALTER COLUMN columnname2 DROP DEFAULT, 
   ALTER COLUMN columnname3 DROP DEFAULT,
   ....