This paper mattered meters along
This address: http://blog.csdn.net/sushengmiyan/article/details/50326259
When using SQL, you want to automatically populate the update time when the data is updated, then how is it implemented in MySQL?
such as creating tables users
CREATE TABLE rs_signupuser ( ID VARCHAR (COMMENT) ' primary key (business function independent) ', USERNAME VARCHAR COMMENT ' name ', Usergender VARCHAR (3) DEFAULT ' 0 ' COMMENT ' sex 0 male 1 female ', Idcardnumber varchar COMMENT ' ID number ', usernation varchar (6) COMMENT ' Nation ', BIRTHDAY DATE COMMENT ' birthday ', C9/>userage INTEGER COMMENT ' age ', mobilephone varchar (one) COMMENT ' mobile number ', BZ VARCHAR (6) COMMENT ' Notes ', Createtime TIMESTAMP DEFAULT current_timestamp COMMENT ' registration time ', createuserid VARCHAR COMMENT ' creator ', PX INTEGER COMMENT ' sort ', updateuserid VARCHAR (COLLATE utf8_bin COMMENT ' update person ', UpdateTime TIMESTAMP DEFAULT Current_ TIMESTAMP on update current_timestamp NULL COMMENT ' update Time ', CONSTRAINT PRIMARY Key (ID), UNIQUE KEY ( ZONECODE,USERZYBM) ) COMMENT = ' Registered user table ';
Wherein, UpdateTime TIMESTAMP DEFAULT current_timestamp on update current_timestamp NULL COMMENT ' update Time ', will be automatically populated at the time of the update. La La. Happy with it.
Do not be happy so early, if you are using the mysql5.4 version, then you create the table when the error, not to mention the update time, see:
ERROR 1293 (HY000): incorrect table definition; There can is only one TIMESTAMP column with Current_timestamp in DEFAULT or on UPDATE clause
If a bird goes wrong, creating a table fails.
Look at the timestamp of version 5.5 document: http://dev.mysql.com/doc/refman/5.5/en/timestamp-initialization.html
One TIMESTAMP
column in a table can has the current timestamp as the default value for initializing the column, as the Auto-u Pdate value, or both. It is not a possible to having the current timestamp being the default value for one column and the Auto-update value for another Column.
You can see that this version has a limit on timestamps.
And look at version 5.7.
Http://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html
There is no such limit. I think that the lower version of the only way to do something else, manually or using a trigger to do the update time this thing. Or just upgrade the version directly to fix the problem.
MYSQL Update time Auto sync vs. Create time default coexistence issues