tags:

views:

23

answers:

2
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [Lending].[uspHMDAUpdateExport] (@BatchId int, @ModifiedById int)
AS
BEGIN
 SET NOCOUNT ON
 SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

 DISABLE TRIGGER Lending.utrHMDAAudit ON Lending.HMDA

 UPDATE Lending.HMDA SET IsExported = 1,ModifiedById = @ModifiedById WHERE BatchId = @BatchId

 ENABLE TRIGGER Lending.utrHMDAAudit ON Lending.HMDA

END

SET QUOTED_IDENTIFIER OFF 
GO
GRANT EXECUTE ON [Lending].[uspHMDALarInfoGet] TO [caApplication] AS [dbo]
GO

Says the DISABLE and ENABLE syntax is wrong. Why?

+1  A: 

It should be

ALTER TABLE Lending.HMDA DISABLE TRIGGER Lending.utrHMDAAudit; 

ALTER TABLE Lending.HMDA ENABLE TRIGGER Lending.utrHMDAAudit;

but is your trigger really named Lending.utrHMDAAudit?

Also

You know that if your update fails in the proc that the trigger will be disabled right? Your proc doesn't have any error handling, a constraint violation will abort the batch and your trigger is disabled

Better to disable and enable the trigger after the proc call and before

SQLMenace
@SQLMenace - According to MSDN the ALTER TABLE isn't required: http://msdn.microsoft.com/en-us/library/ms189748.aspx
dcp
+1  A: 

You need some semicolons (at the end of the statement preceding DISABLE and at the end of the statement before ENABLE)

On a side note setting the isolation to READ UNCOMMITTED and disabling triggers both seem distinctly dubious to me.

In this case the isolation level doesn't seem like it would make any difference to the following statements so is this standard practice in all your procedures? If so are you aware of the potential issues with it?

Regarding the trigger disabling what is to stop another concurrent transaction modifying the table whilst the trigger is disabled?

Martin Smith