devxlogo

Updating a Column with the Current Time Stamp in MySQL

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())
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist