1
我的觸發器由於某種原因插入了4次,而最後一個僅被分組。基本上我想要做的是將信息插入到我的表中tbl_delete_Panel
我想將這些數據分組並將其插入到tbl_delete_panel_Orderin
中。SQL Server插入觸發器不止一次插入
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE Trigger[dbo].[deletePanelSQL]
ON [dbo].[tbl_delete_Panel]
AFTER INSERT
AS
BEGIN
/* Insert Summed Quantity for each stud or track into tbl_delete_panel for deletion. tbl_delete_panel trigger will be triggered */
INSERT INTO tbl_delete_panel_Orderin (Part_Name, OrderID, SumOfQTY)
SELECT
tbl_delete_panel.Part_Name, tbl_delete_panel.OrderID,
Sum(tbl_delete_panel.QTY) AS SumOfQTY
FROM
tbl_delete_panel
GROUP BY
tbl_delete_panel.Part_Name, tbl_delete_panel.OrderID;
END;
您保持插入來自'tbl_delete_panel'完整的行,每次這個觸發器被調用。你應該做的**是看看'Inserted'僞表,它可以包含多行,並插入這些行**(這是由觸發觸發器的語句新插入的) - 不是**整桌**每次! –