kingrichard2005
kingrichard2005

Reputation: 7279

alter stored procedure to use snapshot isolation level

Quick question I have a database with snapshot enabled using

ALTER DATABASE myDB
SET ALLOW_SNAPSHOT_ISOLATION ON

I'm trying to alter an existing stored procedure to use the transaction isolation level to read uncommitted using as follows:

USE [myDB]
GO
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
GO
/****** Object:  StoredProcedure [dbo].[myStoredProcedure]    Script Date: 03/27/2012 11:39:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[myStoredProcedure]

AS
BEGIN
    SELECT *
    FROM someTable
END

RETURN 0

But when I reopen the stored procedure the SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED statement is gone.

USE [myDB]
GO
/****** Object:  StoredProcedure [dbo].[myStoredProcedure]    Script Date: 03/27/2012 11:39:24 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[myStoredProcedure]

AS
BEGIN
    SELECT *
    FROM someTable
END

RETURN 0

Was the transaction level actually set? I expected the statement to still be there after closing and reopening the stored procedure window. Just wanted to verify, thanks.

Upvotes: 0

Views: 2660

Answers (1)

Russell Hart
Russell Hart

Reputation: 1851

You have to put it in the procedure body. If it is outside you are just altering it in that isolation level as opposed to altering the procedure definition to use it.

USE [myDB]
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[myStoredProcedure]

AS
BEGIN
    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

    SELECT *
    FROM someTable
END

Upvotes: 1

Related Questions