RE: Guarantee Transaction Isolation
From: Al (Al_at_discussions.microsoft.com)
Date: 06/30/04
- Next message: Aaron [SQL Server MVP]: "Re: Sorry. I have an SP that accepts a WHERE clause as a parameter. Doesn't work ...kinda"
- Previous message: Otis: "Re: Job step failure notification"
- In reply to: Al: "RE: Guarantee Transaction Isolation"
- Next in thread: Stefan Berglund: "Re: Guarantee Transaction Isolation"
- Reply: Stefan Berglund: "Re: Guarantee Transaction Isolation"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 30 Jun 2004 12:20:01 -0700
I was partly wrong.
What you have will work with SERIALIZABLE isolation, but will not with the default READ COMMITED isolation.
So, you can use either TABLOCKX or HOLDLOCK locking hints. The HOLDLOCK locking hint makes the statment run as if it were at SERIALIZABLE isolation.
"Al" wrote:
> I would guess no.
>
> The first thing to realise is that although you have done a SELECT to get the highest key value, this will NOT stop an INSERT into the Transaction table. I think this would be the case even at SERIALIZABLE isolation. Although this is the highest isolation level, the range lock on the index would NOT prevent an INSERT. However, you can test this with Query Analyzer.
>
> I would use a TABLOCK lock hint in the select, and ensure that I kept my transaction as short as possible.
>
> Al
>
> "Stefan Berglund" wrote:
>
> > Consider the following table and stored procedure:
> >
> > CREATE TABLE ShowTime..Transactions (
> > ShowID SMALLINT NOT NULL,
> > TransactionID INTEGER IDENTITY(1,1) NOT NULL,
> > ShowNumber SMALLINT NOT NULL,
> > ToShowNumber SMALLINT NOT NULL,
> > ClassID SMALLINT NOT NULL,
> > Type TINYINT NOT NULL,
> > Charge DECIMAL(19,4) NOT NULL,
> > Param VARCHAR(50) NOT NULL DEFAULT '',
> > TransactionTime SMALLDATETIME NOT NULL DEFAULT GETDATE(),
> > Scratched BIT NOT NULL DEFAULT 0)
> >
> >
> > CREATE PROCEDURE _ResetTransactionID
> > @ShowID SMALLINT AS
> >
> > SET NOCOUNT ON
> > DECLARE @Seed INTEGER SET @Seed = 0
> > BEGIN TRAN
> > SELECT @Seed=MAX(TransactionID) FROM Transactions WHERE ShowID=@ShowID
> > DBCC CHECKIDENT ('Transactions', RESEED, @Seed)
> > COMMIT TRAN
> > GO
> >
> > Does wrapping this operation in a transaction guarantee in a
> > multi user environment that no other operation can insert into
> > the table (thereby altering the TransactionID) between the two
> > statements inside the transaction? Or do I need additional
> > precautions?
> >
> >
> > ---
> > Stefan Berglund
> >
- Next message: Aaron [SQL Server MVP]: "Re: Sorry. I have an SP that accepts a WHERE clause as a parameter. Doesn't work ...kinda"
- Previous message: Otis: "Re: Job step failure notification"
- In reply to: Al: "RE: Guarantee Transaction Isolation"
- Next in thread: Stefan Berglund: "Re: Guarantee Transaction Isolation"
- Reply: Stefan Berglund: "Re: Guarantee Transaction Isolation"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|