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

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

    While you can't do this with DATETIME in the default definition, you can simply incorporate a select statement in your insert statement like this:

    INSERT INTO Yourtable (Field1, YourDateField) VALUES('val1', (select now()))
    

    Note the lack of quotes around the table.

    For MySQL 5.5

提交回复
热议问题