I have 2 tables (A,B), and 1 query
My query is something like this
- Read From A
- Update B with this data from A
- Using the updated table B, set final value of A.
Example execution can be find in below question:
Proper way to keep a single data in sql server?
Now since all the process is connected, this query should not be executed twice at the same time, or by 2 different users until the process ends. How do I prevent this ? Or does it already work securely like this?
Use transaction lock :
during the transaction execution, any try to read or write from/to tables will timeout…