MySQL single-table multi-timestamp Set the default problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.