MySQL TIMESTAMP (timestamp) detailed explanation

Source: Internet
Author: User

When you create a table that has a type of field timestamp in the table, the statement is generated by default:

CREATE TABLE ' test ' (  ' id ' int (one) default null,  ' ctime ' timestamp not null default Current_timestamp on UPDATE CU Rrent_timestamp) Engine=innodb DEFAULT CHARSET=GBK

Assuming that there are two field types of timestamp, the resulting statement is:

CREATE TABLE ' test ' (  ' id ' INT (one) default null,  ' ctime ' TIMESTAMP not null default Current_timestamp on UPDATE CU Rrent_timestamp,  ' utime ' TIMESTAMP not NULL default ' 0000-00-00 00:00:00 ') engine=innodb default CHARSET=GBK
TIMESTAMP setting defaults are default Current_timestamp,

TIMESTAMP settings as the table changes and your own active update is on update current_timestamp

A table can have at most only one field set Current_timestamp (current time)

1. TIMESTAMP DEFAULT current_timestamp on UPDATE current_timestamp

Refreshes the data column when new records are created and existing records are changed

2. TIMESTAMP DEFAULT Current_timestamp

Set this field to the current time when creating a new record, but do not refresh it when you change it later

3. TIMESTAMP on UPDATE current_timestamp

Set this field to 0 when creating a new record, and refresh it later when you change it


Viewmode=contents "style=" Color:rgb (255, 153, 0); Text-decoration:none; font-family:arial; font-size:14px; line-height:26px; " >itmyhome

Source: http://blog.csdn.net/itmyhome1990/article/details/39342245


MySQL TIMESTAMP (timestamp) detailed explanation

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.