There can is only one TIMESTAMP column with Current_timestamp in DEFAULT or on UPDATE clause

Source: Internet
Author: User

To build a table statement:

CREATE TABLE Test_table (
ID integer NOT NULL auto_increment primary key,
stamp_created timestamp default ' 0000-00-00 00:00:00 ',
stamp_updated timestamp default now in Update Now ()
);

Test:

 Mysql> Insert IntoTest_table(stamp_created,stamp_updated) Values(Null, Null); 
QueryOk, 1Row affected(0.06Sec)

Mysql> Select * FromT5;
+----+---------------------+---------------------+
|Id|stamp_created|stamp_updated|
+----+---------------------+---------------------+
| 2 | 2009-04-30 09:44:35 | 2009-04-30 09:44:35| +----+---------------------+------- --------------+
2in set ( 0.00 Sec)

/span>
Mysql> UpdateTest_tableSetId= 3 whereId= 2; 
QueryOk, 1 row affected (0.05< Span class= "PLN" > Sec) rows Matched:1 changed : 1< Span class= "PLN" > warnings: 0
Mysql> Select * FromTest_table;
+----+---------------------+---------------------+
|Id|stamp_created|stamp_updated|
+----+---------------------+---------------------+
| 3 | 2009-04-30 09:44:35 | 2009-04-30 09:46:59|
+----+----------- ----------+---------------------+
2< Span class= "PLN" > rows in set (0.00 sec ) /span>

Reference here:

http://stackoverflow.com/questions/267658/having-both-a-created-and-last-updated-timestamp-columns-in-mysql-4-0

There can is only one TIMESTAMP column with Current_timestamp in DEFAULT or on UPDATE clause

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.