Timestamp---Automatic Update modification time and record first insertion time

Source: Internet
Author: User

Automatic Update modification Time:

int , b timestamp on update current_timestamp); MySQLSelect1, Current_timestamp;
Select  from Z; +------+---------------------+| A    | b                   |+------+---------------------+|    1 --: |+------+---------------------+ 1 inch Set (0.00 sec)
mysql> INSERT INTO ZSelect 2, Current_timestamp; Query OK,1Row affected (0.18sec) Records:1Duplicates:0Warnings:0MySQL>Select* fromZ;+------+---------------------+| A | b |+------+---------------------+|1| .- .- -  -: -: $||2| .- .- -  -: +: to|+------+---------------------+2Rowsinch Set(0.00Sec
mysql> Update ZSeta=a+ - whereA=1; Query OK,1Row affected (0.20sec) Rows matched:1Changed:1Warnings:0MySQL>Select* fromZ;+------+---------------------+| A | b |+------+---------------------+|101| .- .- -  -: +: -||2| .- .- -  -: +: to|+------+---------------------+2Rowsinch Set(0.00Sec

Record first insertion time:

Mysql> CREATE TABLE X (aint, b timestampdefaultcurrent_timestamp); Query OK,0Rows Affected (0.22sec)MySQL>Select* fromx; EmptySet(0.00sec) MySQL> INSERT into X (a) VALUES (1); Query OK,1Row affected (0.18sec) MySQL>Select* fromx;+------+---------------------+| A | b |+------+---------------------+|1| .- .- -  -: -:Geneva|+------+---------------------+1Rowinch Set(0.00sec) MySQL> INSERT into X (a) VALUES (2); Query OK,1Row affected (0.19sec) MySQL>Select* fromx;+------+---------------------+| A | b |+------+---------------------+|1| .- .- -  -: -:Geneva||2| .- .- -  -: -: *|+------+---------------------+2Rowsinch Set(0.00Sec

Timestamp---Automatic Update modification time and record first insertion time

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.