MySQL, the same table multiple timesatmp field settings default, often error.
A table can have only one field that sets the default.
However, sometimes only one field setting default will also error.
Report: Incorrect table definition; There can is only one TIMESTAMP column with Current_timestamp in DEFAULT or on UPDATE clause
But check the code and find that only one timestamp set the default.
CREATE TABLE Seckill ( ' seckill_id ' BIGINT not NUll auto_increment COMMENT ' commodity stock id ', ' Name ' VARCHAR (+) not NULL COMMENT ' commodity name ', ' Number ' int not NULL COMMENT ' inventory quantity ', ' Start_time ' TIMESTAMP not NULL COMMENT ' seconds kill start time ', ' End_time ' TIMESTAMP not NULL COMMENT ' seconds kill end Time ', ' Create_time ' TIMESTAMP not NULL DEFAULT current_timestamp COMMENT ' creation time ', PRIMARY KEY (seckill_id), Key Idx_start_time (start_time), Key Idx_end_time (End_time), Key Idx_create_time (Create_time) ) Engine=innodb auto_increment=1000 DEFAULT Charset=utf8 comment= ' second kill inventory table '; |
The reason is that when you set the timestamp to on Updatecurrent_timestamp, the other timestamp fields need to explicitly set the default value
But if you have two timestamp fields, but only the first one is set to Current_timestamp and the second does not have a default value, MySQL can build the table successfully, but not in the reverse ...
Change into
CREATE TABLE Seckill ( ' seckill_id ' BIGINT not NUll auto_increment COMMENT ' commodity stock id ', ' Name ' VARCHAR (+) not NULL COMMENT ' commodity name ', ' Number ' int not NULL COMMENT ' inventory quantity ',
' Create_time ' TIMESTAMP not NULL DEFAULT current_timestamp COMMENT ' creation time ',
' Start_time ' TIMESTAMP not NULL COMMENT ' seconds kill start time ', ' End_time ' TIMESTAMP not NULL COMMENT ' seconds kill end Time ', PRIMARY KEY (seckill_id), Key Idx_start_time (start_time), Key Idx_end_time (End_time), Key Idx_create_time (Create_time) ) Engine=innodb auto_increment=1000 DEFAULT Charset=utf8 comment= ' second kill inventory table ';
|
The first timestamp is set to default, then the default setting is not available. And there can only be one column setting default.
MySQL single-table multi-timestamp Set the default problem