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
  • 31,815
  • 47
  • 169
  • 296
  • 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
  • 72,128
  • 12
  • 122
  • 148
2

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

a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843