If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > lock table for insert with increment number

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-12-06, 03:38
fab01 fab01 is offline
Registered User
 
Join Date: Mar 2006
Posts: 17
lock table for insert with increment number

Hi !!
here's my problem with DB2 version 7.1 (zos, cobol, cics transaction)
I have a table client which contains 3 cols (id_client, sequence_number, data)
the primary key is id_client and sequence number.
When i created a new row and a new client, the sequence_number = 1
When i created a new row with old client, the sequence_number = (max of sequence number of the same id_client +1).
The solution is :
1/ to do a select max of sequence_number
2/ add 1 to this sequence_number
3/ make the insert.
But i'm afraid if there are 2 persons who do the same things at the same time, they will have the same sequence number. What about concurrency ?
Thanks a lot.
Reply With Quote
  #2 (permalink)  
Old 04-12-06, 08:17
przytula przytula is offline
Registered User
 
Join Date: Nov 2004
Posts: 374
sequence

or create a sequence and retrieve this unique nbr or
select .... for update --> this will acquire a higher lock and avoid any other application to do a select.. (lock wait)
__________________
Best Regards, Guy Przytula
DB2/ORA/SQL Services
DB2 DBA & Advanced DBA Certified
DB2 Dprop Certified
http://users.skynet.be/przytula/dbss.html
Reply With Quote
  #3 (permalink)  
Old 04-12-06, 12:17
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
If you retrieve a duplicate sequence number, you will get an RI error when you try the insert since you have a PK, so there will be no data integrity problem. You can code retry logic if that specific error code is returned (duplicate PK).
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On