删除Datetime字段的默认值

时间:2022-10-22 18:13:55

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 ?

现有的MySQL表有一个DateTime字段,该字段不为null,默认值设置为“0001-00-00 00:00 00:00”。是否可以更改此表以删除DateTime字段的默认值?

2 个解决方案

#1


23  

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

是的,您可以使用如下所示的ALTER TABLE语句来删除默认值:

alter table your_table 
  alter column your_column drop default;

#2


3  

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

从表中的多个datetime列中删除默认值:

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

#1


23  

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

是的,您可以使用如下所示的ALTER TABLE语句来删除默认值:

alter table your_table 
  alter column your_column drop default;

#2


3  

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

从表中的多个datetime列中删除默认值:

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