Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Row Locking

Author  Topic 

CTG
Starting Member

1 Post

Posted - 2008-11-24 : 18:28:23
Hi I have a c# application using sql 2005.
there are 2 methods associate with that table
-Select
-Update

I d like to lock the records that are selected for others to update.
I d like to be able to unlock the records when updates are done.
I also like to know how I can figure out that using select can tell me if that particular record is clocked or not.

Cheers


Yohoo

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-11-25 : 04:21:12
moved from article discusion forum.

___________________________________________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.1 out!
Go to Top of Page

darkdusky
Aged Yak Warrior

591 Posts

Posted - 2008-11-25 : 07:37:37
SQL Server manages locks itself. There is usually no need to explicitly lock rows.
However if you wish you can force the locking behaviour using lock hints. See:
http://blog.sqlauthority.com/2007/04/27/sql-server-2005-locking-hints-and-examples/

Explicit locks may cause deadlocks if conflicts arise. If you leave it to SQL Server this is less likely.
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2008-11-25 : 07:56:13
Yeah - what darkdusky said. DB locks are how the database implements concurrency and consistency. Usually just the fact you are in a transaction doing updates will lock the relevant things. What you are describing sounds like it is a requirement of your application and must be analysed and coded as per your requirements. Some applications take the view that mostly things don't change and just make sure the record they are updating is the same as that that they read, which is pretty easy (use a row timestamp). If you want a long-term lock-update-release across transactions then you'll need to design something (including tidy-up of abandoned updates etc).
Go to Top of Page
   

- Advertisement -