Db2 lock for a row using a field

IBM's flagship relational database management system

Db2 lock for a row using a field

Postby sam_jj12 » Fri Dec 14, 2018 11:57 pm

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.
Posts: 18
Joined: Sat Nov 21, 2015 12:02 am
Has thanked: 0 time
Been thanked: 0 time

Re: Db2 lock for a row using a field

Postby Jim Ruddy » Thu Dec 20, 2018 3:35 am

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.

Jim Ruddy
Posts: 5
Joined: Tue Jan 16, 2018 11:45 pm
Has thanked: 0 time
Been thanked: 0 time

Return to DB2


  • Related topics
    Last post