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

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

    For all who use the TIMESTAMP column as a solution i want to second the following limitation from the manual:

    http://dev.mysql.com/doc/refman/5.0/en/datetime.html

    "The TIMESTAMP data type has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC. It has varying properties, depending on the MySQL version and the SQL mode the server is running in. These properties are described later in this section. "

    So this will obviously break your software in about 28 years.

    I believe the only solution on the database side is to use triggers like mentioned in other answers.

提交回复
热议问题