TIMESTAMP has two properties, namely Current_timestamp and on UPDATE Current_timestamp two, respectively, the following are used:
1.current_timestamp
When you want to perform an insert operation to the database, if you have a timestamp field property set to
Current_timestamp, the current system time is inserted regardless of whether the field has a wooden set value.
2.ON UPDATE Current_timestamp
When the update operation is performed, and the field has the on Update Current_timestamp property. The value of the field is updated to the time of the current update operation, regardless of whether the value has changed.
Variants of the timestamp
1.TIMESTAMP DEFAULT current_timestamp on UPDATE current_timestamp
Refreshes the data column when new records are created and existing records are modified
2.TIMESTAMP DEFAULT Current_timestamp
This field is set to the current time when a new record is created, but it is not refreshed when you modify it later
3.TIMESTAMP on UPDATE Current_timestamp
Set this field to 0 when creating a new record, and refresh it later when you modify it
4.TIMESTAMP DEFAULT ' Yyyy-mm-dd hh:mm:ss ' on UPDATE current_timestamp
Set this field to the given value when you create a new record, and refresh it later when you modify it
Use triggers to override:
CREATE TABLE' Example ' (' ID ')INTEGERUNSIGNED not NULLauto_increment, ' created 'TIMESTAMP not NULL DEFAULT Current_timestamp, ' lastupdated 'DATETIME not NULL, PRIMARY KEY(' id ')) ENGINE=InnoDB;DROP TRIGGER IF EXISTS' Update_example_trigger ';D elimiter//CREATE TRIGGER' Update_example_trigger ' beforeUPDATE on' Example ' forEach ROWSETNEW ' lastupdated '=Now ()//DELIMITER;
MySQL timestamp type field current_timestamp and on UPDATE current_timestamp properties