i want the system to generate and store the time stamp to a column in a table when the insert query is fired in MySQL. how to make it happen?
Asked
Active
Viewed 75 times
-3
-
1Looks like a duplicate of: http://stackoverflow.com/questions/31096248/inserting-a-time-into-mysql-database-in-java?rq=1 – T-Heron Feb 05 '17 at 12:50
-
1Possible duplicate of [Why there can be only one TIMESTAMP column with CURRENT\_TIMESTAMP in DEFAULT clause?](http://stackoverflow.com/questions/4489548/why-there-can-be-only-one-timestamp-column-with-current-timestamp-in-default-cla) – Dario Feb 05 '17 at 16:08
1 Answers
0
- Insert the current timestamp to a column 'ts' while inserting a row
CREATE TABLE t1 ( ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
- Insert the current timestamp to column 'ts' while inserting a new row and update the current timestamp in column 'ts' while updating data in that row
CREATE TABLE t1 (
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP );
More details on the below link
https://dev.mysql.com/doc/refman/5.5/en/timestamp-initialization.html

Sk_
- 1,051
- 8
- 18