Updating entry WITHOUT updating timestamp

前端 未结 5 456
旧时难觅i
旧时难觅i 2020-12-02 16:38

I have a timestamp in a mysql table with attribute \"ON UPDATE CURRENT_TIMESTAMP\". Is there a way to manually disable updating the timestamp on a special occasion? (eg: upd

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 17:05

    To make your table/timestamp auto-update:

    ALTER TABLE myTable
    CHANGE myTimestampColumn
            myTimestampColumn TIMESTAMP NOT NULL
                           DEFAULT CURRENT_TIMESTAMP 
                           ON UPDATE CURRENT_TIMESTAMP;
    

    To make it not auto-update:

    ALTER TABLE myTable
    CHANGE myTimestampColumn
            myTimestampColumn TIMESTAMP NOT NULL
                           DEFAULT CURRENT_TIMESTAMP;
    

    NOTE: The "default current_timestamp" part just sets it to the current stamp at default time, since the field is not-null. You can remove both the not null and the default, if you like.

提交回复
热议问题