Auto-update timestamp field

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)
);

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>