Faircube Networks - Custom programming projects, internet consulting, web design, and various other multimedia and graphic design solutions.
 
Home arrow MySQL arrow Order of columns in a create statement
Order of columns in a create statement

Can the order of the columns in a create statement 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.

 

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

Hints: Need mm-dd-yyyy hh:mm:ss format?

  select a,b,DATE_FORMAT(timeUpdate,'%m-%d-%Y %T'),DATE_FORMAT(timeEnter,'%m-%d-%Y %T') from t;
  +------+------+---------------------------------------+---------------------------------+
  | a| b| DATE_FORMAT(timeUpdate,'%m-%d-%Y %T') | DATE_FORMAT(timeEnter,'%m-%d-%Y %T') |
  +------+------+---------------------------------------+---------------------------------+
  |3 |2 | 04-15-2004 19:14:36   | 04-15-2004 19:15:07  |
  |3 |2 | 04-15-2004 19:14:39   | 04-15-2004 19:15:07  |
  |5 |5 | 00-00-0000 00:00:00   | 04-15-2004 19:15:53  |
  |1 |2 | 00-00-0000 00:00:00   | 04-15-2004 19:20:15  |
  +------+------+---------------------------------------+---------------------------------+
  4 rows in set (0.00 sec)

 

 
 
Home | Services | Portfolio | Support | Prices | About Us | Privacy | Terms | Website Resources | Legal
Copyright © 1999-2007 Faircube Networks Inc. All Rights Reserved.