我正在读一些触发器的代码。
CREATE TRIGGER No_DeleteCustomers
ON Customers
INSTEAD OF DELETE
AS
IF @@ROWCOUNT = 0
RETURN
RAISERROR('No deleting allowed', 11, 1)但是我很困惑。@@ROWCOUNT不是用来显示最后一条语句中受影响的行数的吗?这如何阻止我从表中删除行?
发布于 2017-01-29 16:50:56
让我们逐行遍历触发器的代码来演示它是如何工作的:
IF @@ROWCOUNT = 0 -- if the number of rows to be deleted is 0 then...
RETURN -- return
-- if still running...
RAISERROR('No deleting allowed', 11, 1) -- raise an error to the caller希望这能有所帮助!
https://stackoverflow.com/questions/41914990
复制相似问题