Page 1 of 1

Db2 lock for a row using a field

PostPosted: Fri Dec 14, 2018 11:57 pm
by sam_jj12
Hi all.
Is there any way a row can be locked in a table using a primary key column of a table. so i will not stop or affect other rows which needs updation.
..any command or option are there.?

At all the places people will be looking on test cases or at times they query and there is a possibilty others might use others case for there testing which affects tester effort in creating the scenario.

Re: Db2 lock for a row using a field

PostPosted: Thu Dec 20, 2018 3:35 am
by Jim Ruddy
The only way I can recall to lock a row is to open a cursor on a select statement something like


(I apologize if I have the syntax wrong but this should give you a starting point)

and issue the fetch on the cursor. As long as the cursor in your program does not move off of that row, it will remain locked.

Of course, you have to have row level locking and have to make sure you don't cause your lock to escalate to table and all of the associated caveats.