Christian
Christian

Reputation: 28125

MSSQL Database-level versioning

Ideally you should be familiar with MSSQL Row-Level Versioning.

My question is, is there an existing mechanism (or is it possible to create something similar) to get a database version? I would prefer an incremental number (like ROWVERSION) but I'd be perfectly happy with just a hash of the last query that modified the database (INSERT or UPDATE).

Upvotes: 0

Views: 80

Answers (1)

simon at rcl
simon at rcl

Reputation: 7344

There's nothing built in that lets you do this.

You could have a trigger on every table for Delete, Insert, and Update, which updates a single column on a table with a single row, adding 1 each time, but this will become a bottle-neck and slow down performance. I wouldn't recommend it.

Alternatively, you could possibly do something with the Last Modified Time on the mdf and ldf files, but you'll probably need elevated access to get to that and it wouldn't be tied to any individual SQL statement. It also wouldn't take into account anything that SQL has got cached and not written as yet, so maybe it wouldn't work anyway.

So, I can't see a reliable and non-intrusive way of doing this. However, I can't actually see why you'd need to - what would do with something that said version = 123456? What if it was version = 123457?

Upvotes: 1

Related Questions