Turn from:automatic generation and update of timestamp in MySQL
The timestamp type in MySQL can set default values, just like any other type.
1, Automatic Update and insert to the current time:
Table:
---------------------------------
Table Create Table
------ --------------------------
CREATE TABLE ' T1 ' (
Data:
1 2007-10-08 11:53:35
2 2007-10-08 11:54:00
INSERT into T1 (p_c) Select 3;
Update T1 Set P_c = 2 where p_c = 2;
Data:
1 2007-10-08 11:53:35
2 2007-10-08 12:00:37
3 2007-10-08 12:00:37
2, automatic insert to the current time, but does not automatically update.
Table:
---------------------------------
Table Create Table
------ ---------------------------
CREATE TABLE ' T1 ' (
Data:
INSERT into T1 (p_c) Select 4;
Update T1 Set P_c = 3 where p_c = 3;
1 2007-10-08 11:53:35
2 2007-10-08 12:00:37
3 2007-10-08 12:00:37
4 2007-10-08 12:05:19
3. Cannot have two fields in a table the default value is the current time, otherwise an error occurs. But the others can.
Table:
---------------------------------
Table Create Table
------ --------------------------
CREATE TABLE ' T1 ' (
Data:
1 2007-10-08 11:53:35 0000-00-00 00:00:00
2 2007-10-08 12:00:37 0000-00-00 00:00:00
3 2007-10-08 12:00:37 0000-00-00 00:00:00
4 2007-10-08 12:05:19 0000-00-00 00:00:00
Automatic generation and update of timestamp in MySQL