faqts : Computers : Databases : MySQL : Tips and Tricks

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 5 people (100%) answered Yes
Recently 5 of 5 people (100%) answered Yes

Entry

If I have 2 TIMESTAMP fields, does the order make a difference?

Jun 23rd, 2004 06:56
Mike Chirico, http://sourceforge.net/project/showfiles.php?group_id=79320&package_id=115696


I have 2 TIMESTAMP fields, does the order  make a difference?  YES.

 
       create table t (
          a int,
          b int,
          timeUpdate timestamp,
          timeEnter timestamp );

The first timestamp will always be the "automatically generated" time. 
So if the record is updated, or inserted, this time gets changed. If 
the order is changed, "timeEnter" is before "timeUpdate", 
then,  "timeEnter" would get updated.  First timestamp column updates 
automatically.

Note, in the table above timeEnter will only get updated if passed a 
null value.  But, timeUpdate doesn't need a NULL value.

         insert into t (a,b,timeEnter) values (1,2,NULL);

See TIP 3 on the source URL above.