Is there a way to get DateTime value from timestamp type column?

后端 未结 8 687
执笔经年
执笔经年 2020-12-06 17:30

I need a select from table which does not have column that tells when row was inserted, only timestamp column (values like: 0x0000000000530278). Some data was i

相关标签:
8条回答
  • 2020-12-06 18:05

    I know it is too late but might help someone else.

    Timestamp/RowVersion can be casted to BigInt but in any mean it cannot be compared to datetime.

    Following statement is taken from MSDN

    The Transact-SQL rowversion data type is not a date or time data type. timestamp is a deprecated synonym for rowversion.

    For more detail refer here

    0 讨论(0)
  • 2020-12-06 18:09

    To identify new rows by timestamp you need to keep track of the timestamps that were there beforehand. In a pinch you could:

    • Restore a previous version somewhere else.
    • Copy the data from both tables into a scratch database.
    • Identify the inserted data from the timestamps present in one but not the other.

    With a minor risk of false positives if anything else has been going on in the DB this will get you a reasonably good difference.

    For a more robust check you could calculate MD5 or SHA-1 hashes with Hashbytes on the row contents to give you a difference with a very low probability of collision (see this wikipedia article on Birthday attacks for a discussion of this problem).

    0 讨论(0)
提交回复
热议问题