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 > Oracle > Concurrent user update

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-28-03, 00:56
mchih mchih is offline
Registered User
 
Join Date: Nov 2002
Posts: 98
Concurrent user update

a conceptual queston; i seem to remember reading it somewhere but can't recall the solution in Oracle:

say 2 users retrieve the same record for read.
user A updated the record first.
what would happen when user B tries to update the same record?

i seem to remember user B would not be able to update because the data he retrieves is out-of-date. Is that right?

Best Regards,

Mark
Reply With Quote
  #2 (permalink)  
Old 01-28-03, 05:23
NoviceNo1 NoviceNo1 is offline
Registered User
 
Join Date: Jan 2003
Location: Woking
Posts: 107
Re: Concurrent user update

Quote:
Originally posted by mchih
a conceptual queston; i seem to remember reading it somewhere but can't recall the solution in Oracle:

say 2 users retrieve the same record for read.
user A updated the record first.
what would happen when user B tries to update the same record?

i seem to remember user B would not be able to update because the data he retrieves is out-of-date. Is that right?

Best Regards,

Mark
Hi,
For this you need to lock your records. That is lock it while selecting.
select * from emp where empno < 2000 FOR UPDATE;
The FOR UPDATE clause will lock the selected rows and prevent
the other user from update/delete.
__________________
nn
Reply With Quote
  #3 (permalink)  
Old 01-28-03, 05:29
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: Concurrent user update

Quote:
Originally posted by mchih
a conceptual queston; i seem to remember reading it somewhere but can't recall the solution in Oracle:

say 2 users retrieve the same record for read.
user A updated the record first.
what would happen when user B tries to update the same record?

i seem to remember user B would not be able to update because the data he retrieves is out-of-date. Is that right?

Best Regards,

Mark
What happens depends on how the retrieve is done: just SELECT, or SELECT FOR UPDATE.

1) SELECT (without FOR UPDATE)

- User A selects the record
- User B selects the record
- User A updates the record
- User B tries to update the record - is blocked by user A and hangs
- User A commits
- User B's update now completes
- User B commits

There is now a potential "lost update", because user A's change may have been overridden by user B's.

2) SELECT FOR UPDATE

- User A selects the record FOR UPDATE
- User B selects the record FOR UPDATE - is blocked by user A and hangs
- User A updates the record
- User A commits
- User B now gets the record (including A's updates)
- User B updates the record
- User B commits
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #4 (permalink)  
Old 01-28-03, 08:52
mchih mchih is offline
Registered User
 
Join Date: Nov 2002
Posts: 98
thanks andrew

it's the 2nd solution i was looking for

Best Regards

Mark
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