Auto-update timestamp field

August 13th, 2008

I keep on forgetting this SQL query. So I decided to put it here as a reference:

CREATE TABLE testtbl (
   id int AUTO_INCREMENT,
   created_on TIMESTAMP DEFAULT 0,
   updated_on TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON
                    UPDATE CURRENT_TIMESTAMP,
   first_name varchar(25),
   last_name varchar(25),
   primary key(id)
);
Share this Post

  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati

Tags: , ,

Leave a Reply