MySQL TIMESTAMP (timestamp) detailed

Source: Internet
Author: User

When you create a table with a field type of timestamp, the default build statement for that field is:

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

If there are two field types 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 automatically update as the table changes is on update current_timestamp

There can be at most one field set in a table 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 modified

2. TIMESTAMP DEFAULT Current_timestamp

This field is set to the current time when a new record is created, but it is not refreshed when you modify it later

3. TIMESTAMP on UPDATE current_timestamp

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


Reprint Please specify source: http://blog.csdn.net/itmyhome1990/article/details/39342245


MySQL TIMESTAMP (timestamp) detailed

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.