Reference table Structure
CREATE TABLE ' T_baby ' (
' baby_id ' int (one) not NULL auto_increment,
' user_id ' int (one) is not NULL,
' Nickname ' varchar (+) DEFAULT NULL,
' Avatar ' varchar (+) DEFAULT ',
' Sex ' int (2) unsigned not NULL DEFAULT ' 0 ' COMMENT ' 0: unknown; \\n 1: Male; \\n 2: Female. ‘,
' Birthday ' datetime not NULL,
' creater ' varchar (+) DEFAULT ',
' Create_time ' timestamp not NULL DEFAULT Current_timestamp,
' Update_time ' timestamp null DEFAULT null on update Current_timestamp,
' Is_delete ' bigint () DEFAULT NULL COMMENT ' 0 ',
' Updater ' varchar (+) DEFAULT NULL,
PRIMARY KEY (' baby_id ')
) Engine=innodb auto_increment=10000000 DEFAULT charset=utf8mb4;
When we create business tables, we usually need to set create_time and update_time, but usually we need to set the time in the code to insert the database.
After the Current_timestamp field is set, MySQL automatically sets the current system time assignment to the property field when the Insert data
When the on Update Current_timestamp field is set, MySQL automatically sets the current system time assignment to the property field when the data is updated and changes successfully
Create_time Setting the Current_timestamp property
Update_time setting the on UPDATE Current_timestamp property
We don't need to manually assign values to these two parameters in code to save a certain amount of code.
MySQL Auto set create_time and Update_time