I am looking for something similar to rowversion but for the whole table : a unique number automatically generated that can be used to know if table has changed.
Eg :
SELECT TABLE_VERSION('FOO')
0x00000000000007D2
INSERT INTO FOO (...) VALUES (1, 'Hello world')
SELECT TABLE_VERSION('FOO')
0x00000000000007D5
Does it exists in SQL Server ?
If not, is there any alternative ? Somethings that allow to track changes on a column would be great too. I have been thinking of using HASHBYTES, but unfortunately it only gives hash for a single column value not for the whole column.
There is not such a thing in SQL Server, however you can implement it easly with triggers. I have used it to assist cache invalidation for web apps.
first create the table etags:
Insert a value for the
Foo
table:Then create a trigger for the
foo
table that updates the etag value when table changes