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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 sql server rowlock question
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sguerra
Starting Member

3 Posts

Posted - 09/23/2005 :  19:41:58  Show Profile  Reply with Quote
I need to know how does sql server locks the rows of a select.

With a statement like this:
**************************************
BEGIN TRAN

select max(numero_reg)
from cont_registro with (holdlock,rowlock)
where serial_dia = 15

//// do my stuff

COMMIT TRAN
**************************************

Is sql server locking all the rows of the where clause
"where serial_dia = 15"

OR

Is sql server locking ONLY one row that complies whit
"max(numero_reg)" and has "serial_dia = 15"

Please help

Santiago G.

tkizer
Almighty SQL Goddess

USA
38200 Posts

Posted - 09/23/2005 :  19:44:14  Show Profile  Visit tkizer's Homepage  Reply with Quote
You should begin tran until after your SELECT statement. All data gathering should be outside of the transaction.

SQL Server starts at row-level locking and escalates as needed. You can read all about locking in SQL Server Books Online if you need detailed information about it.

Tara
Go to Top of Page

sguerra
Starting Member

3 Posts

Posted - 09/23/2005 :  19:48:24  Show Profile  Reply with Quote
Could you be more specific (like an example), since I have read a lot of information about locking and i don't understand it very well.

What i need is to lock all rows from table cont_registro that have serial_dia = 15.

Santiago G.
Go to Top of Page

eyechart
Flowing Fount of Yak Knowledge

USA
3575 Posts

Posted - 09/23/2005 :  20:20:32  Show Profile  Reply with Quote
SQL Server may not put a rowlock on those rows, it might use a page lock instead. It all depends.

You can change (or try to change) sql servers locking behavior by using locking hints. Check BOL for details, here is a start: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/acdata/ac_8_con_7a_1hf7.asp


-ec
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000