If I want each new entry into my db to be automatically timestamped, would I set the Field Type to “timestamp” and have the Default value set to “CURRENT_TIMESTAMP”?
Is this the correct method?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
That is correct. In SQL code that would be:
CREATE TABLE `table` ( ... `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, ... )
Method 2
Yes, this method is correct:
create table t(Id int, ts timestamp default current_timestamp) insert into t(Id) values (1) select * from t 1;2010-09-01 09:20:09:000
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0