2

I would like to include an integer version field in my table, auto-incrementing on each update made to a row. Is it possible to do this in MySQL?

Please note that I'm not talking about a TIMESTAMP, which is not reliable as two concurrent updates might happen during the same second.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • What is the use exactly? All it will tell you is the number of times a particular row has been updated. You can't revert to a previous version. – Jai Jun 09 '11 at 10:52
  • It would be used for versioning entities in an ORM. – BenMorel Jun 09 '11 at 16:48

2 Answers2

3

Yes it is. The more general problem is called slowly changing dimensions.

Denis de Bernardy
  • 75,850
  • 13
  • 131
  • 154
2

The only way (I can think of) to do this is a (before-update) trigger that automatically increments the column value.