MySQL single table multiple timestamp set default problem

Source: Internet
Author: User
Tags table definition

MySQL, the same table multiple timesatmp fields set default, often an error.

A table can have only one field that sets default.

But sometimes only one field setting default also complains.

Will report: incorrect table definition; There can be only one TIMESTAMP column with Current_timestamp in DEFAULT or on UPDATE clause

But checking the code, found that only one timestamp set default.

For example:

The code is as follows Copy Code

Create Table Dxs_product
(
   pid                   int NOT NULL auto_increment comment ' Product ID ',
   pname  & nbsp;             varchar comment ' product name ',
   istop                int Comment ' sticky ',
   begintoptime         timestamp comment ' Sticky time ' ,
   endtoptime           timestamp comment ' Sticky time ',
   publishtime          Timestamp default Current_ TIMESTAMP comment ' release time ',
   primary KEY (PID)

The reason is that when you set a 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, MySQL can also build the table, but the reverse is not ...

Change into:

The code is as follows Copy Code

Create Table Dxs_product
(
   pid                   int NOT NULL auto_increment comment ' Product ID ',
   pname  & nbsp;             varchar comment ' product name ',
   istop                int Comment ' sticky ',
   publishtime          timestamp default Current_timestamp comment ' release time ',
   begintoptime         Timestamp comment ' sticky time ',
   endtoptime           Timestamp comment ' sticky time ',
   primary KEY (PID)

There will be no more errors.

The first timestamp is set to default, and the following settings default is not available. And you can only have one column set default.

Related Article

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.