Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locking row from a view

Status
Not open for further replies.

malaygal

IS-IT--Management
Feb 22, 2006
192
US
Need to lock a record after I select it and unlock it (even without updating).
I also need to check if record is lock.

Been googling this for quite some time now, found some articles on locking row from table but not from a view.
When I implement on my view, did not seem to work.

BEGIN TRAN
SELECT * FROM myTable WITH (UPDLOCK,READPAST)
WHERE myID = someValue
COMMIT TRAN

--CHECK IF ID IS LOCKED
SELECT myID FROM myTable WITH(NOLOCK)
WHERE myID NOT IN
(
SELECT myID FROM myTable WITH(READPAST)
)

Tried different combination of (UPDLOCK,READPAST) i.e HOLDLOCK, ETC..

Any Help will be greatly appreciated.


 
I suspect your issue is you are using the view in an application and want it to lock that record if a users is reviewing it. Is that correct?
If so you would need to start a transaction in your application. Not the view.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top