Using timestamp to implement database to process the time difference problem of the same record __ database

Source: Internet
Author: User
At work, we often process a row of records to find that there are multiple threads at the same time (SQL Server), although the system takes the appropriate locking policy to prevent contention deadlock, but for a frequent processing of records, due to the system's multithreaded mechanism, So when multiple transactions process the same record, because the transaction is of different size and time is sequential, this may result in dirty reading of the database, and it is found that using timestamp is a better solution by studying multiple methods, that is, adding a column of fields to the most frequently used table, the type is timestamp, After the addition of the system will automatically generate the corresponding unique value, if the data records have any changes, timestamp value will be adjusted accordingly, using this method, we at the beginning of the transaction process, the first record of the old timestamp value, such as real changes in the data, check the timestamp is the same, If the same, the data is not dirty to continue processing, if the difference is that the processing of other threads before the modification, this time can be discarded to ensure that the data security consistent.

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.