0

我在 SQL Server 2008 中创建了一个触发器

CREATE TRIGGER [dbo].[ITEM_UOM_DELETE] ON
   [dbo].[ITEM_UOM] INSTEAD OF DELETE
   AS
      declare @rowc int
      set @rowc = (select count(*) from stock, deleted where 
      item = deleted.itemcode and uom = DELETED.MAINUNIT AND DOCTYPE <> 'OP')
         if @rowc > 0
         begin
           raiserror('Unit is in Use Cannot Delete', 16, 1)
           rollback transaction
         end

在执行此触发器时,它会给出错误输出

Msg 50000, Level 16, State 1, Procedure ITEM_UOM_DELETE, Line 11
Unit is in Use Cannot Delete
Msg 3609, Level 16, State 1, Line 1
事务在触发器中结束。该批次已中止。

我只想要定义的错误

单位正在使用中无法删除

如何删除错误“事务在触发器中结束。批次已中止。?

4

1 回答 1

0
CREATE TRIGGER [dbo].[ITEM_UOM_DELETE] ON
[dbo].[ITEM_UOM] INSTEAD OF DELETE
AS
BEGIN

declare @rowc int
select @rowc=count(*) from stock

if @rowc <= 0
begin
deleted uom from [ITEM_UOM] uom inner join deleted on uom.item = deleted.itemcode 
and uom.MAINUNIT = DELETED.MAINUNIT where uom.DOCTYPE <> 'OP'
end
else
begin
raiserror('Unit is in Use Cannot Delete', 16, 1)
end

end
于 2012-10-22T07:07:40.790 回答