Maintain business data synchronization

Source: Internet
Author: User

During database processing, you always need to be exposed to data synchronization and modification issues. Sometimes we need to ensure business data synchronization during business processing (generally, this situation includes statistical fields, that is to say, You need to calculate the field of the subsequent value based on the previous value). For example, after two people query a record at the same time, add 1 to it and save it to the database, this may cause storage problems. Therefore, you need to synchronize the data. The following three methods can be used:

1. Add a version field, get this field during query, and Add 1 after modification. Other modifications in the future need to be compared. If they are different, the storage fails (additional comparisons are required)

2. Depending on the database mechanism, lock the data to be modified (this method will cause the database access bottleneck)

3. Use a composite SQL statement to modify the data during storage, for example, updata A tem1 set tem1.filed = (select tem2.filed + 1 from a tem2 where tem1.id = tem2.id) Where tem1.id = 1;

 

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.