views:

18

answers:

1

Hello,

I would like to implement a basic versioning system in a MySQL table. Let's imagine a simple table with 2 columns: name (pk) and price. I thought I would simply add a column 'version' and add it to the primary key. Then I would catch all the UPDATE's and do an insert instead, incrementing the version number.

First, is this possible ? Can I make a trigger BEFORE UPDATE and do an insert and cancel the UPDATE ? What would be the syntax ? Second, is this idea ok ? how would you achieve this ?

Thank you for your help, Barth

+1  A: 

You cannot cancel the update. I would keep table with versions separately from the "main" table, and would insert into this table new record when main table gets updated. Or even easier - use insert with new version number instead of update without any triggers.

spbfox
Thank you for your answer. I will go for a separate table. I prefer not to rely on people using insert with new version number, this is error prone.
Barth
Agree. If you are not the exclusive owner of the code, separate table is safer.
spbfox