Use timestamp in SQL Server

Source: Internet
Author: User

SQL Server connection books

SQL ServerTimestampThe data type is independent of the time and date. SQL ServerTimestampIt is a binary number that indicates the relative sequence of data modifications in the database. ImplementationTimestampThe data type was initially designed to support SQL Server restoration algorithms. Each time a page is modified, the current @ dbts value is used to mark it once, and then @ dbts is added with 1. This is enough to help the recovery process determine the relative order of page modifications,TimestampThe value has no relationship with the time.

 

 

TimestampThis type of data represents the automatically generated binary number, which is unique in the database.TimestampIt is generally used to add version stamps to table rows. The storage size is 8 bytes.

Transact-SQLTimestampData Types andTimestampDifferent data types. SQL-92TimestampThe data type is equivalent to transact-SQL.DatetimeData type.

Microsoft SQL Server may modify the transact-SQL statement in future versions.TimestampThe behavior of the Data Type so that it is consistent with the behavior defined in the standard. By then, the currentTimestampThe data type will useRowversionReplace the data type.

Microsoft SQL Server 2000 introducesTimestampData TypeRowversionSynonym. Use DDL statements as much as possibleRowversionDo not useTimestamp.RowversionRestricted by the behavior of Data Type synonyms. For more information, see Data Type synonyms.

In the create table or alter table statementTimestampColumn names are provided for data types:

       CREATE TABLE ExampleTable (PriKey int PRIMARY KEY, timestamp)

If no column name is provided, SQL Server generatesTimestamp.RowversionData Type synonyms do not have such behavior. SpecifyRowversionThe column name must be provided.

One table can have only oneTimestampColumn. Each insert or update containsTimestampColumn row,TimestampThe values in the column are updated. This attribute enablesTimestampColumns are not suitable for use as keys, especially they cannot be used as primary keys. Any updates to the row will be changed.TimestampTo change the key value. If the column belongs to the primary key, the old key value is invalid, and the foreign key that references the old value is no longer valid. If the table is referenced in a dynamic cursor, all updates change the row position of the cursor. If this column belongs to the index key, all updates to the data row will also lead to index updates.

Cannot be emptyTimestampColumns are semantically equivalentBinary (8)Column. Can be emptyTimestampColumns are semantically equivalentVarbinary (8)Column.

 

 

Go </P> <p> Create Table t_test_timestamp (<br/> ID int identity (1, 1) not null, <br/> name varchar (200) null, <br/> Status timestamp <br/>) <br/> go </P> <p> insert t_test_timestamp (name) values ('Nelson '); <br/> insert t_test_timestamp (name) values ('sum'); <br/> insert t_test_timestamp (name) values ('lily '); <br/> select * From t_test_timestamp <br/> go <br/> Update t_test_timestamp set name = 'bob' where id = 1 <br/> select * From t_test_timestamp <br/> go

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.