K
K
Konstantin2018-10-16 00:32:27
MySQL
Konstantin, 2018-10-16 00:32:27

How to properly use TIMESTAMP as ROWVERISON in MySQL?

How to properly use TIMESTAMP as ROWVERISON in MySQL?
Do I need to set timestamp length and constraint as CURRENT_TIMESTAMP?
As far as I remember, timestamp will allow you to store a timestamp up to the year 2038. After 2038 - will this type lose its meaning?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2018-10-16
@Rsa97

Just define the field type as TIMESTAMP. By default, the field will be automatically populated when a row is created and will change when it changes.
As for 2038, how much do you use programs written in 1998? Until the age of 38, everything will change more than once.

R
res2001, 2018-10-16
@res2001

Using a timestamp for these purposes, you run the risk of getting a data mismatch in the event of a system time failure or something else (switching to summer / winter, changing the time zone, ...).
I would use a regular auto-increment field for rowversion, and a datetime (or timestamp) field just as the timestamp of the change.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question