MySQL TIMESTAMP (TIMESTAMP) details, mysqltimestamp

Source: Internet
Author: User

MySQL TIMESTAMP (TIMESTAMP) details, mysqltimestamp

When creating a table, if a field type in the table is TIMESTAMP, the default statement for generating this field is:

CREATE TABLE `test` (  `id` int(11) DEFAULT NULL,  `ctime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP) ENGINE=InnoDB DEFAULT CHARSET=gbk

If two fields are of the TIMESTAMP type, the generated statement is:

CREATE TABLE `test` (  `id` INT(11) DEFAULT NULL,  `ctime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,  `utime` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00') ENGINE=INNODB DEFAULT CHARSET=gbk
The Default value of TIMESTAMP is Default CURRENT_TIMESTAMP,

The TIMESTAMP is set to automatically update on update CURRENT_TIMESTAMP as the table changes.

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

1. timestamp default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP

This data column is refreshed when a new record is created and an existing record is modified.
 
2. timestamp default CURRENT_TIMESTAMP

This field is set to the current time when a new record is created, but it will not be refreshed when it is modified later.

3. timestamp on update CURRENT_TIMESTAMP

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


Reprinted please indicate the source: http://blog.csdn.net/itmyhome1990/article/details/39342245



How to convert mysql timestamp to timestamp

Select to_timestamp ('2017-11-02 04:05:10 ', 'yyyy-MM-DD HH: MI: ss ')
From dual;

Is the timestamp type of mysql from January 1, 1970 to the present?

Yes, the current number of milliseconds

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.