Database Row Operations (2), Database Row Operations

Source: Internet
Author: User

Database Row Operations (2), Database Row Operations

Continued:

You can arrange it FOR not only UPDATE, but also an UPDATE flag.

For example:

To update a TABLE, the field ID is the primary key. Then A performs the following operations:

Select id from table where * FOR UPDATE

Update table set * where id = *;
A first locks the Qualified Data, then performs the update operation, followed by COMMIT and so on.

Question:

At TIME1, A understands that the column ID = 1 in the TABLE of the database does not meet the condition. At TIME2, A is ready to perform the preceding operation to modify the condition, but B also finds the condition, however, the TABLE is changed at TIME1.5. At this time, A changes the data after B changes.

Solution:

A reference flag is required, which is assumed to be the UPD field.

A. to modify the data with ID = 1 In the table, you must first query the UPD field value for ID = 1;

Select upd from table where id = 1

Assume that the UPD value is vals =;

Select id from table where id = 1 and upd = vals FOR UPDATE

Then, the update operation is complete.

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.