Monday, April 06, 2009

Oracle sql code , row lock to prevent other users while editing data

Some databases, SQL Server included, use locks to prevent users from seeing uncommitted modifications. In these systems if UserA is modifying some set of data, then UserB and all the rest of the users must wait until UserA is done modifying that data before they can even get a shot at reading the data, let alone modifying it.
 
They are used like this:
 
SELECT COUNT(UserID)
FROM Users WITH (NOLOCK)
WHERE Username LIKE 'foobar'
 
and
 
UPDATE Users WITH (ROWLOCK)
SET Username = 'fred' WHERE Username = 'foobar'
 

2 comments:

akhil said...

hi i am creating a multi user inventory software. when a user types first few words of an item, a grid of related items are shown. user selects an item from grid & it is this item thet i want to lock. this item is to be used only by the current usr and no one else. while using rowlock, all rows in result set are locked.plz help... thank you

Santhosh Babu | Project Manager : www.decatrend.com | said...

you must keep the field in seperate table

Adobe News