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

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

    I think it simple in mysql since mysql the inbuilt function called now() which gives current time(time of that insert).

    So your query should look like similarly

    CREATE TABLE defaultforTime(
        `creation_time`     DATETIME DEFAULT CURRENT_TIMESTAMP,
        `modification_time` DATETIME default now()
    );
    

    Thank you.

提交回复
热议问题