I have an sql server table with a timestamp column. Is there a way to force the timestamp column to change without an actual update of the record?
The reason I am asking is because I want the record’s timestamp to change when a record is inserted/updated/deleted in a child table.
Timestamp may not be the best way to go about doing this. If not, what should I do? I don’t want to use datetime because I don’t feel that’s a good way of versioning. I don’t want to use an integer, because I don’t want to have to read the value to increment it.
Suggestions?
While that does technically require a read, I don’t see any problems with it.
You could always just update to the same value:
which will trigger rowversion update as well.
ADDITION: You could do a view with the max rowversion of the children:
But, no, you can’t directly update a rowversion column (though you could implement your own updatable with @@DBTS, binary(8) and INSTEAD OF triggers…)
No, really it doesn’t. 😉 It’s too much work when you could just update to the same value instead or use a view. Those are the 2 easiest options.
But, to be complete, a binary(8) column with a default of @@DBTS (which returns the database version number), and an AFTER UPDATE trigger that also updates the binary column to the new @@DBTS will give you a psuedo-rowversion type that you can then update manually. It’d be no faster or better than just updating some other column to it’s same value though.