Sql server 执行触发器时,不显示任何内容。。。为什么?
所以我写了下面的触发器Sql server 执行触发器时,不显示任何内容。。。为什么?,sql-server,triggers,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), @
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
语句中是否有错误?还是我在触发器的工作原理上遗漏了什么
谢谢你的帮助 触发器不返回任何结果集。删除触发器应该做什么?触发器是否不返回
SELECT
命令中的所有内容?是。它将读取值并分配给变量。触发器不是用来将结果返回给客户端的。啊,我明白你的意思了。那么,如何将结果返回给客户机呢?您不需要。不是通过触发器。返回结果,即查询或存储过程的作业。听起来您需要的是存储过程而不是触发器。您试图在这里实现什么?触发器不会返回任何结果集。删除触发器应该做什么?触发器是否不返回SELECT
命令中的所有内容?是。它将读取值并分配给变量。触发器不是用来将结果返回给客户端的。啊,我明白你的意思了。那么,如何将结果返回给客户机呢?您不需要。不是通过触发器。返回结果,即查询或存储过程的作业。听起来您需要的是存储过程而不是触发器。你想在这里实现什么?