执行触发时,不显示任何内容......为什么?

时间:2017-11-26 03:26:22

标签: sql-server triggers

所以我写了以下触发器......

CREATE TRIGGER deleteOrderTrigger
ON order_details
FOR DELETE

AS
-- Set the variables you'll use during the trigger
DECLARE @orderId int, 
        @productId int, 
        @quantityRemoved int,
        @productName varchar(50),
        @stock int

-- Assign the variables to the selected columns
SELECT @productId = deleted.product_id,
       @productName = products.name,
       @quantityRemoved = deleted.quantity,
       @stock = SUM(products.quantity_in_stock) + @quantityRemoved


FROM deleted 
LEFT JOIN products ON products.product_id = deleted.product_id
LEFT JOIN order_details ON order_details.order_id = deleted.order_id 

WHERE order_details.order_id = @orderId AND products.product_id = @productId

GROUP BY deleted.product_id, products.name, deleted.quantity

GO

-- Test the trigger

DELETE order_details
     WHERE order_id=10001 AND product_id=25

因此,当我使用上述语句调用触发器时,控制台中不会返回任何内容。这很奇怪,因为我写了我的select语句来返回被删除的内容。

但是,当我尝试返回已删除的值时......实际上它们已被删除(所以我知道该部分有效)但在初始触发器中没有返回任何内容。

我的SELECT声明中有什么问题吗?或者我错过了触发器如何工作的东西?

感谢您的帮助!

0 个答案:

没有答案