Which is better: INSERT NOW () or DEFAULT CURRENT_TIMESTAMP?

What is better in MySQL and why:

for settings

`Time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 

when creating a table


Or:

 INSERT Now() value when we insert a row. 

Added: How about performance?

+4
source share
3 answers

I suggest that the database do the work, so the programmer cannot forget to do an extra insert / update of the column and insert the wrong time.

+5
source

If the "Time" field is mandatory and should never be "null" or "not set", it is better to use it in the table structure (solution 1), instead, if the field can be omitted sometimes, you should use NOW () in the insert request . It depends on your needs ...

+1
source

I looked at this document Error in now () and current_timestamp ()

I suggest using the now () or current_timestamp () function through the project.

0
source

Source: https://habr.com/ru/post/1381379/


All Articles