Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: Updating a Column with the Current Time Stamp in MySQL

Learn how to add the current time from the database when updating a column.


advertisement

This is probably an audit requirement and most of the time it is essential to maintain the creation time. However, passing the current time from an application context may not be a wise idea and it is better to use the time from the database, which will be more precise.

MySQL facilitates this with the NOW() command. It can be used in CREATE TABLE command as below and you can avoid passing data to this column while you are inserting a record.

CREATE TABLE EMP (NAME VARCHAR(30), ID INT(5), CREATION_TIME DATETIME DEFAULT NOW())

Alternatively, you can also use CURRENT_TIMESTAMP in place of NOW().

 

Visit the DevX Tip Bank

 





   
Sridhar M S. is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date