View previous topic :: View next topic |
Author |
Message |
danm Intermediate
Joined: 29 Jun 2004 Posts: 170 Topics: 73
|
Posted: Fri Mar 26, 2010 11:31 am Post subject: Minimize locking |
|
|
In the SQL table, I have 10 departments. In my program, I extract data from 3 join tables for all departments via a single SQL query, process each row then update one of the table (e.g. Time stamp and status). On the other hand, I can loop throught each department and issue 10 SQL query 10 times (i.e. with WHERE DEPT = :DEPT). Will the second approach minimize the chance of locking? |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Fri Mar 26, 2010 12:32 pm Post subject: |
|
|
danm,
I would prefer the cursor JOIN on 2 tables(non update tables) and update table 3 with your join condition on where clause accordingly.
Kolusu |
|
Back to top |
|
|
danm Intermediate
Joined: 29 Jun 2004 Posts: 170 Topics: 73
|
Posted: Tue Mar 30, 2010 8:35 am Post subject: |
|
|
Kolusu,
I do need to join the 3rd table because I need columns from all 3 tables to determine if the 3rd table need to be updated. |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Tue Mar 30, 2010 10:09 am Post subject: |
|
|
danm,
Exactly my point. You can join the 2 tables and try updating the 3rd with the join keys. If found then you would update or else you would get a sqlcode of 100 and you would process the next. So you are not holding up any tables for a longer period of time.
Kolusu |
|
Back to top |
|
|
|
|