Updating a Column with the Current Time Stamp in MySQL

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())
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: