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.
| Author |
Topic |
|
tedmanowar
Starting Member
31 Posts |
Posted - 2007-05-17 : 09:54:14
|
| Hello all,Does anyone know the lifetime of a ROWLOCK when stated in a sproc like this one below ?ALTER PROCEDURE GetLastId @idType nvarchar(50) ASBEGIN SET NOCOUNT ON; DECLARE @lastId int SET @lastId= (SELECT lastId FROM LastIds WITH (ROWLOCK) WHERE idType=@idType) SET @lastId=@lastId+1 UPDATE LastIds SET lastId=@lastId WHERE idType=@idType SELECT (@lastID) as LastIDENDGOI am wondering whether the lock will exist until the end of the sproc or not...Many thanks in advance...TedManowar |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-05-17 : 09:56:15
|
| no it won't.it will exist until the end of your select statement whic you can also rewrite like thisSELECT @lastId = lastIdFROM LastIds WITH (ROWLOCK)WHERE idType=@idType_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenp |
 |
|
|
tedmanowar
Starting Member
31 Posts |
Posted - 2007-05-17 : 09:57:59
|
| Thanks for your quick reply man!Do you know of a way to lock a particular row for the duration of the sproc ?TedManowar |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-05-17 : 10:03:58
|
| try with this:begin transelect ....from ... WITH (ROWLOCK, XLOCK)...update...commit_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenp |
 |
|
|
|
|
|