Increment version column on update

3.1k views Asked by At

Must I increment a integer version column within an update (before) trigger?

Or is there something like ON UPDATE AUTOINCREMENT similar to ON UPDATE CURRENT_TIMESTAMP within table column declaration?

In SQL there is something like a rowversion column type for that case.

1

There are 1 answers

2
juergen d On BEST ANSWER

Try

delimiter //
create trigger inc_trg before update on your_table
for each row 
begin    
  set new.some_column = new.some_column + 1;
end
//
delimiter ;