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.