Ugy Astro
Ugy Astro

Reputation: 417

Auto-store datetime() value in select insert query mysql

need an advice, how to auto-store datetime value for my historyActivity table in select insert mysql query. This is an example:

INSERT INTO history_sequence(CODE, LAST_MOUNTH, LAST_VALUE) SELECT CODE, MOUNTH, VALUE FROM seq WHERE CODE = CODEVALUE

i just want to add datetime to see time when the data inserted. Need help please

Upvotes: 2

Views: 192

Answers (1)

Alex Woolford
Alex Woolford

Reputation: 4563

You can do this in the MySQL table definition:

ALTER TABLE history_sequence ADD inserted TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;

When records are inserted into the table table, the inserted column gets automatically populated with the current timestamp.

Upvotes: 1

Related Questions