Home > database > Consult about dynamic SQL in the safety of concurrent scenarios
Consult about dynamic SQL in the safety of concurrent scenarios
Time:09-23
Such as update table1 set filed1=field1-1 where the field - 1 & gt;=0 and id=1, could you tell me all this statement there will be risk high concurrency, Appear this kind of circumstance, for example, filed1=1, two statements judgment field1=1 at the same time, this time will do subtraction 1-1, 0 and 1 at a time, I think the success of this statement is to read you are exclusive lock the row or table, but there is no professional train of thought
CodePudding user response:
Don't worry, will line up, When two of the same KEY update statement, it is the exclusive row locks.
You can use two clients, cross perform the following tests: START the TRANSACTION The update table1 set filed1=field1-1 where the field - 1 & gt;=0 and id=1 COMMIT
CodePudding user response:
There is something wrong with the statement in the top, where the field should be field1, or from the new write an unambiguous The update mytable set myfiled=myfield - 1 where myfield 1 & gt;=0 and id=1