문제

I'd like to load some file into MySQL, and I want to assign a single timestamp to all rows that were loaded within the same load operation. To do this, can I simply assign a default value like this?

CREATE TABLE test (
    test TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    something VARCHAR(255) NOT NULL
);

When I tried the timestamps did seem to be identical, but of course I can't be sure if this is guaranteed. I went through the documentation but couldn't find an answer. Also is there a better way to do this?

도움이 되었습니까?

해결책

CURRENT_TIMESTAMPE is a synonym for NOW()

NOW() returns a constant time that indicates the time at which the statement began to execute

Since it's based on statement execution time, you are good to go.

다른 팁

The above SQL statement guarantee that whenever you insert a row in the table you the the instantaneous time, thus can be shown like:

SELECT CURRENT_TIMESTAMP;

If you run this command each second you will notice the you get the most updated time on each instance.

PS: you can also use constant UTC_TIMESTAMP to get current time in UTC timezone.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top