January 26, 2014 at 7:29 am
Hi,
I have a question regarding the timestamp type in SQL Server. As far as I know the timestamp column holds an ever increasing number (every update or insert increments the @@DBTS value and writes this to the inserted or updated row). Now I have the question, when or if this global value gets resetted or if it is ever increasing, also after a restart of the sql server?
Best regards!
January 26, 2014 at 11:54 am
vip.blade (1/26/2014)
Hi,I have a question regarding the timestamp type in SQL Server. As far as I know the timestamp column holds an ever increasing number (every update or insert increments the @@DBTS value and writes this to the inserted or updated row). Now I have the question, when or if this global value gets resetted or if it is ever increasing, also after a restart of the sql server?
Best regards!
The following URL...
http://technet.microsoft.com/en-us/library/ms187366.aspx
... says...
This timestamp is guaranteed to be unique in the database.
Since the datatype is VARBINARY and, not including MAX datatypes, would allow a value of 2568000-1 as well as the guarantee of uniqueness in a database, I'm thinking that it will never be reset and that a restart of SQAL Server will also not reset it.
As for what happens when it does reach a value of 2568000, I suspect that even the fastest computer couldn't reach that mark in hundreds of lifetimes.
[Edit] Please see corrected information further below.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 27, 2014 at 9:18 pm
Jeff Moden (1/26/2014)
vip.blade (1/26/2014)
Hi,I have a question regarding the timestamp type in SQL Server. As far as I know the timestamp column holds an ever increasing number (every update or insert increments the @@DBTS value and writes this to the inserted or updated row). Now I have the question, when or if this global value gets resetted or if it is ever increasing, also after a restart of the sql server?
Best regards!
The following URL...
http://technet.microsoft.com/en-us/library/ms187366.aspx
... says...
This timestamp is guaranteed to be unique in the database.
Since the datatype is VARBINARY and, not including MAX datatypes, would allow a value of 2568000-1 as well as the guarantee of uniqueness in a database, I'm thinking that it will never be reset and that a restart of SQAL Server will also not reset it.
As for what happens when it does reach a value of 2568000, I suspect that even the fastest computer couldn't reach that mark in hundreds of lifetimes.
Mmm - the storage for a TIMESTAMP column is actually 8 bytes - equivalent of a BINARY(8). If definite does not allow for values up to 2568000-1.
As for uniqueness - yes, the values are unique within a database. If you backup/restore the database to another server or as a database with a new name on the same instance, the next value generated on both the original database and the restored database will be the same.
January 27, 2014 at 9:53 pm
Since a TIMESTAMP column is 64 bits, the number of possible unique values = 18,446,744,073,709,551,616 ( 2 to the 64th power ).
Certainly a very large number.
A table with a single byte with that number of rows would be about 134,217,728 TBytes:
-- ((2 to 64th) * 8)/ (1099511627776) /* bytes per TB */
select (power(2.0E,64.0E)*8.0E) / power(1024.0E,4.0E)
That is a DB size well beyond the ability of the current technology to implement (1.3 million 100 TByte drives), but not impossible to imagine in the future.
January 27, 2014 at 10:47 pm
Ah, my apologies. I read that the return datatype of @@DBTS is VARBINARY in BOL and didn't consider the source (TIMESTAMP) is 64 bits. Thanks for the correction.
Guess we'll have to settle for just for a lifetime or two.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 4, 2014 at 12:52 pm
Thanks for all your responses, this helped me a lot!
Best regards!
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy