Re: HOLDLOCK?
From: Kalen Delaney (replies_at_public_newsgroups.com)
Date: 10/22/04
- Next message: Mark: "DB Options Advice."
- Previous message: Stringfellow Hawke: "Re: SqlServer Log question"
- In reply to: Greg Sullivan: "HOLDLOCK?"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 22 Oct 2004 08:34:39 -0700
Hi Greg
You have to be in a transaction for HOLDLOCK to hold anything, but you can
explicitly create a transaction with BEGIN TRAN.
BEGIN TRAN
SELECT ... FROM tab with (HOLDLOCK)
...
SELECT ... FROM tab
COMMIT TRAN
this will guarantee that the data you read in the first select will not be
changed until the COMMIT TRAN.
-- HTH ---------------- Kalen Delaney SQL Server MVP www.SolidQualityLearning.com "Greg Sullivan" <saucerattack@hotmail.com> wrote in message news:7bfe64e8.0410220704.26224b70@posting.google.com... >I guess the software engineers here don't have much better to do than > debate the extreme limits of database concurrency. So, the question > has come up about how to ensure data has not changed between two > select statements within a stored procedure. Take the following as an > example: > > create procedure exampleProcedure > as > begin > select fieldOne > from tableOne > > select columnOne > from tableTwo > > end > go > > How can I ensure that no one has come along and updated tableTwo > between the time the procedure acquires a lock on tableOne and it > acquires a lock on tableTwo? My first thought is to use a HOLDLOCK, > but everything that I've read indicates that a HOLDLOCK persists the > lock the duration of a transaction. And in this case, I have no > isert/update/delete statements so I am not technically in a > transaction. > > Is this issue just academic? Personally, I think they are making a > mountain out of a molehill, but I'm not able to quote scripture (BOL) > at them. > > Any ideas?
- Next message: Mark: "DB Options Advice."
- Previous message: Stringfellow Hawke: "Re: SqlServer Log question"
- In reply to: Greg Sullivan: "HOLDLOCK?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|