开发者

Trigger Code on a table in my ERP Database

My ERP Vendor has the following trigger on a table:

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TRIGGER [dbo].[SOItem_DeleteCheck]
ON [dbo].[soitem]
FOR DELETE
AS 
BEGIN
    DECLARE @RecCnt int, @LogInfo varchar(256)

    SET @RecCnt = (SELECT COUNT(*) FROM deleted)

    IF @RecCnt > 150
    BE开发者_如何学CGIN
        RAISERROR (54010, 18, 1, 'SOItem') WITH LOG
        ROLLBACK TRANSACTION
    END

    SET @LogInfo = 'Deleting ' + LTRIM(STR(@RecCnt)) + ' Rows From SOItem'

    EXEC LogDeletes @LogInfo
END
GO

This seems very inefficient to me. Doesn't select count(*) take longer than Count(specific field)?


Honestly even if is is slower, I can run a select stament like that in less than a millisecond on my largest table that has millions of rows which this trigger is unlikely to hit. There is no real performance gain from changing it. I'm curious as to why you would want to rollback any transaction with more than 150 records thoug.


I think in the past there was a benefit to count(1) vs count(*), and we were all taught to use that approach, but at this point it's more about style than performance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜