Automatic generation and update of timestamp in MySQL

Source: Internet
Author: User

Turn from:automatic generation and update of timestamp in MySQL

The timestamp type in MySQL can set default values, just like any other type.
1, Automatic Update and insert to the current time:
Table:
---------------------------------
Table Create Table
------ --------------------------

CREATE TABLE ' T1 ' (  




Data:

1 2007-10-08 11:53:35
2 2007-10-08 11:54:00

INSERT into T1 (p_c) Select 3;
Update T1 Set P_c = 2 where p_c = 2;



Data:

1 2007-10-08 11:53:35
2 2007-10-08 12:00:37
3 2007-10-08 12:00:37

2, automatic insert to the current time, but does not automatically update.

Table:
---------------------------------
Table Create Table
------ ---------------------------

CREATE TABLE ' T1 ' (  




Data:

INSERT into T1 (p_c) Select 4;
Update T1 Set P_c = 3 where p_c = 3;



1 2007-10-08 11:53:35
2 2007-10-08 12:00:37
3 2007-10-08 12:00:37
4 2007-10-08 12:05:19


3. Cannot have two fields in a table the default value is the current time, otherwise an error occurs. But the others can.
Table:
---------------------------------
Table Create Table
------ --------------------------

CREATE TABLE ' T1 ' (  





Data:
1 2007-10-08 11:53:35 0000-00-00 00:00:00
2 2007-10-08 12:00:37 0000-00-00 00:00:00
3 2007-10-08 12:00:37 0000-00-00 00:00:00
4 2007-10-08 12:05:19 0000-00-00 00:00:00

Automatic generation and update of timestamp in MySQL

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.