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.
Db2 lock for a row using a field
-
- Posts: 5
- Joined: Tue Jan 16, 2018 11:45 pm
- Skillset: Retired DB2 for z/OS Developer
Worked on mainframes since 1974
CLIST
REXX
PL/X
PL/I
Assembler
SQL
ISPF - Referer: Google search
Re: Db2 lock for a row using a field
The only way I can recall to lock a row is to open a cursor on a select statement something like
SELECT PRIMARY_KEY
FROM TABLE_X
WHERE PRIMARY_KEY = :KEY_VALUE
FOR UPDATE
(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
SELECT PRIMARY_KEY
FROM TABLE_X
WHERE PRIMARY_KEY = :KEY_VALUE
FOR UPDATE
(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
-
- Similar Topics
- Replies
- Views
- Last post
-
- 1
- 1770
-
by sergeyken
View the latest post
Fri Mar 26, 2021 11:59 pm
-
- 2
- 1573
-
by sergeyken
View the latest post
Sun Jan 26, 2025 3:07 am
-
-
sort card to add zeros to varying alphanumeric field.
by longfall » Thu Mar 09, 2023 12:03 am » in DFSORT/ICETOOL/ICEGENER - 1
- 1821
-
by sergeyken
View the latest post
Thu Mar 09, 2023 2:04 am
-