Automatic timestamp update in MySQL

Source: Internet
Author: User
Create Table 'ts '(
'Ts1' timestamp not null,
'Ts2' timestamp not null default current_timestamp,
'Ts3' timestamp null default null
) Engine = InnoDB default charset = utf8

Error code: 1293
Incorrect table definition; there can be only one timestamp column with current_timestamp in default or on update clause

Execution time: 00: 00: 00: 000
Transfer Time: 00: 00: 00: 000
Total time: 00: 00: 00: 000

Ts1 is the same as ts2 during creation, and only one update is allowed.

Create Table 'ts '(

'Ts2' timestamp not null default current_timestamp,
'Ts3' timestamp null default null
) Engine = InnoDB default charset = utf8
In this way, the updated ts2 will not be automatically updated.

Create Table 'ts '(
'Ts1' timestamp not null,
'Ts3' timestamp null default null
) Engine = InnoDB default charset = utf8
After being inserted, the SQL statement becomes
Create Table 'ts '(
'Ts1' timestamp not null default current_timestamp on update current_timestamp,
'Ts3' timestamp null default null
) Engine = InnoDB default charset = utf8

'Ts1' timestamp not null, => 'ts1' timestamp not null default current_timestamp on update current_timestamp,

At this time, the ts1 field will be automatically updated during the update. If you do not want to update the field, add the default
'Ts2' timestamp not null default current_timestamp,

The default value is 'ts3' timestamp null. default null, not 'ts3' timestamp default null.

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.