MySQL new expression, Time field Timetamp encountered problems

Source: Internet
Author: User
Tags mysql version table definition

When you create a table in MySQL, the following questions are encountered on the newly added field time:

The table statement is as follows:

CREATE TABLESeckill (seckill_idbigint  not NULLAuto_increment COMMENT'Item Stock ID', namevarchar( -) not NULLCOMMENT'Product Name', Number int  not NULLCOMMENT'Inventory Quantity', Start_timetimestamp  not NULLCOMMENT'seconds kill turn on time', End_timetimestamp  not NULLCOMMENT'seconds to kill end time', Create_timetimestamp  not NULL DEFAULT Current_timestampCOMMENT'creation Time',PRIMARY KEY(seckill_id),KeyIdx_start_time (start_time),KeyIdx_end_time (end_time),Keyidx_create_time (Create_time)) ENGINE=InnoDB auto_increment= +COMMENT='seconds to kill inventory table';

Execute the above statement and return the error:

Incorrect table definition; There can is only one TIMESTAMP column with the Current_timestamp in DEFAULT or on UPDATE clause.

The MySQL version I am using is 5.5. Query for the reason:

Changes in MySQL 5.6.5 (2012-04-10, Milestone 8)

Previously, at most one TIMESTAMP column per table could is automatically initialized or updated to the current date and T Ime. This restriction has been lifted. Any TIMESTAMP column definition can has any combination of the DEFAULT current_timestamp and on UPDATE current_timestamp Clau Ses. In addition, these clauses now can is used with DATETIME column definitions. For more information, see Automatic Initialization and Updating for TIMESTAMP and DATETIME.

This means: Timestamp does not add the default value, and the build table statement is changed to:

CREATE TABLESeckill (seckill_idbigint  not NULLAuto_increment COMMENT'Item Stock ID', namevarchar( -) not NULLCOMMENT'Product Name', Number int  not NULLCOMMENT'Inventory Quantity', Start_timetimestamp DEFAULT 0  not NULLCOMMENT'seconds kill turn on time', End_timetimestamp DEFAULT 0  not NULLCOMMENT'seconds to kill end time', Create_timetimestamp  not NULL DEFAULT Current_timestampCOMMENT'creation Time',PRIMARY KEY(seckill_id),KeyIdx_start_time (start_time),KeyIdx_end_time (end_time),Keyidx_create_time (Create_time)) ENGINE=InnoDB auto_increment= +COMMENT='seconds to kill inventory table';

You can create a success.

MySQL new expression, Time field Timetamp encountered problems

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.