Knowledge Walls
John Peter
Pune, Maharashtra, India
Automatic insert and update timestamp on Mysql table's
7331 Views
Example with Create Table Query
CREATE TABLE table_name
(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(20) NOT NULL,
modified_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
Example with Alter Table Query
ALTER TABLE table_name
MODIFY COLUMN
`modified_on` TIMESTAMP NOT NULL
DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP;
Notes 
Default CURRENT_TIMESTAMP is putting current time when record insert on table.
ON UPDATE CURRENT_TIMESTAMP is putting current time when record update on table.

  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details