How do you set a default value for a MySQL Datetime column?

后端 未结 26 2183
野的像风
野的像风 2020-11-22 01:55

How do you set a default value for a MySQL Datetime column?

In SQL Server it\'s getdate(). What is the equivalant for MySQL? I\'m using MySQL 5.x if tha

26条回答
  •  灰色年华
    2020-11-22 02:36

    If you have already created the table then you can use

    To change default value to current date time

    ALTER TABLE  
    CHANGE COLUMN   DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP;
    

    To change default value to '2015-05-11 13:01:01'

    ALTER TABLE  
    CHANGE COLUMN   DATETIME NOT NULL DEFAULT '2015-05-11 13:01:01';
    

提交回复
热议问题