触发不在生产中烧制,但在非生产中烧制

时间:2012-06-02 22:55:23

标签: sql-server tsql triggers sql-server-2008-r2

我有一个触发器,在非生产中解决问题,但同样的确切代码无法在生产中触发。我已经确认它没有被禁用,我已经完成了跟踪,看它甚至没有在生产中执行..我已经检查了相关的OBJECTPROPERTY元素,它们是相同的。我确认代码是一样的。我已经确认相同的插件来自应用程序。以下是此触发器的代码:

/****** 
  Object:  Trigger [dbo].[tr_trigger_ins]    
  Script Date: 06/02/2012 16:51:51 
******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO

CREATE TRIGGER [dbo].[tr_trigger_ins] ON [dbo].[table_1]
FOR INSERT
AS
BEGIN
  UPDATE table_2
    SET col_1 =
      CASE 
        WHEN i.col_2 = '0' THEN 0 ELSE 1
      END
  FROM INSERTED i
  INNER JOIN table_3 pa 
    ON i.col_3 = pa.col_3 AND pa.col_4 = 'ispublic'
  INNER JOIN table_4 pp  
    ON i.col_5 = pp.col_5
  INNER JOIN table_2 cs
    ON pp.col_6 = cs.col_6
END
GO

下面是一个触发器,它是在两个环境中执行的同一个表上的insert而不是insert:

/****** 
  Object:  Trigger [dbo].[tr_trigger_before_ins]    
  Script Date: 06/02/2012 16:55:52 
******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER OFF
GO

CREATE TRIGGER [dbo].[tr_trigger_before_ins] ON [dbo].[table_1]
INSTEAD OF INSERT
AS
BEGIN
  INSERT INTO table_1
    SELECT * FROM INSERTED
    WHERE col_3 in (73, 199)
END
GO

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:0)

首先确保未禁用触发器:

ENABLE Trigger tr_trigger_ins ON dbo.table_1;
GO

答案 1 :(得分:0)

最终归结为复制问题。交易的顺序与预期的顺序不同。一旦我们在触发器逻辑中适应这一点,它就能很好地工作。