Reputation: 17905
I have a column of type timestamp
which updates every time record updated.
We have some specific logic for syncronizing data and I'd like to store timestamp's value in other table so I can compare to source later. Can't make new column of type timestamp
as it's auto-updated.
Which SQL type should I use in TableB for maximum performance and quicker CASTs on comparisons?
Upvotes: 0
Views: 100
Reputation: 67291
Taken from the docs
timestamp is the synonym for the rowversion data type and is subject to the behavior of data type synonyms. In DDL statements, use rowversion instead of timestamp wherever possible. For more information, see Data Type Synonyms (Transact-SQL).
and
The timestamp syntax is deprecated.
and
Is a data type that exposes automatically generated, unique binary numbers within a database. rowversion is generally used as a mechanism for version-stamping table rows. The storage size is 8 bytes.
So putting this together: Think of TIMESTAMP
(which should be ROWVERSION
) as a meaningless 8-byte binary. If you really want to do something with it, you can store it as 8-byte binary or you can convert it to a type with a length of 8 bytes. In this case I'd suggest BIGINT
.
Upvotes: 1
Reputation: 379
First, understand that timestamp is NOT a value of type date and time, but rather a unique identifier based on this type of data.
I suggest you review the documentation Date and Time Data Types and Functions (Transact-SQL) and choose the type of data that best suits your needs. This could be DATETIME2, DATETIMEOFFSET, DATETIME
Upvotes: 0