Mysql多个时间戳列更新

时间:2012-01-04 07:40:02

标签: php mysql

考虑一下:

    +---------------+--------------+------+-----+-------------------+-----------------------------+
    | Field         | Type         | Null | Key | Default           | Extra                               |
    +---------------+--------------+------+-----+-------------------+-----------------------------+
    | email_address | varchar(100) | NO   | PRI | NULL              |                             |
    | create_date   | timestamp    | NO   |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
    | optin_date    | timestamp    | YES  |     | NULL              |                             |
    | optout_date   | timestamp    | YES  |     | NULL              |                             |
    +---------------+--------------+------+-----+-------------------+-----------------------------+

使用PHP,如何使optin_dateoptout_date列存储当前时间戳?

1 个答案:

答案 0 :(得分:3)

您只能有一个current_timestamp列。对于第二个,您必须在插入/更新时使用触发器。

http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html