Is TimeStamp column unique?

后端 未结 3 1682
别跟我提以往
别跟我提以往 2021-01-18 07:07

Is TimeStamp unique in all rows?

Does it have a unique index on it?

相关标签:
3条回答
  • 2021-01-18 07:39

    From the MSDN article, emphasis mine:

    Timestamp is a data type that exposes automatically generated, unique binary numbers within a database. timestamp is generally used as a mechanism for version-stamping table rows. The storage size is 8 bytes. The timestamp data type is just an incrementing number and does not preserve a date or a time. To record a date or time, use a datetime data type.

    It also provides this interesting note:

    Duplicate timestamp values can be generated by using the SELECT INTO statement in which a timestamp column is in the SELECT list. We do not recommend using timestamp in this manner.

    In SQL server 2008 and later, the timestamp type has been renamed to rowversion, presumably to better reflect its purpose and value.

    0 讨论(0)
  • 2021-01-18 07:41

    timestamp is a data type that exposes automatically generated binary numbers, which are guaranteed to be unique within a database. timestamp is used typically as a mechanism for version-stamping table rows. The storage size is 8 bytes.


    For more info, check THIS article.

    0 讨论(0)
  • 2021-01-18 07:43

    The docs says

    unique binary numbers within a database

    But in practice you can run into situations where this statement is not true. Since the value is generated from a database global counter you might run into problems when restoring databases and or using timestamp in tables in tempdb.

    You can see the next value:

    Select @@DBTS
    

    Until SQL Server 2000 there was an undocumented command to change the value

    DBCC CHECKDBTS (dbId, newTimestamp)
    

    To change the timestamp in non ancient verswions of SQL server see this answer:

    https://dba.stackexchange.com/a/11088/149485

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