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

后端 未结 26 2185
野的像风
野的像风 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:40

    In version 5.6.5, it is possible to set a default value on a datetime column, and even make a column that will update when the row is updated. The type definition:

    CREATE TABLE foo (
        `creation_time`     DATETIME DEFAULT CURRENT_TIMESTAMP,
        `modification_time` DATETIME ON UPDATE CURRENT_TIMESTAMP
    )
    

    Reference: http://optimize-this.blogspot.com/2012/04/datetime-default-now-finally-available.html

提交回复
热议问题