eg:
CREATE TRIGGER DeleteCode ON [dbo].[StandardCode]
FOR DELETE
AS
if (select count(*) from deleted )>1
begin
raiserror('警告!删除记录有多条!',16,1)
rollback transaction
end
CREATE TRIGGER DeleteCode ON [dbo].[StandardCode]
FOR DELETE
AS
if (select count(*) from deleted )>1
begin
raiserror('警告!删除记录有多条!',16,1)
rollback transaction
end
CREATE TRIGGER DeleteCode ON [dbo].[StandardCode]
FOR DELETE
AS
if (select count(*) from deleted )>1
begin
raiserror('警告!删除记录有多条!',16,1)
rollback transaction
end
As
set @MinID = (Select Min(InstoreListID) from Instore_List where InstoreID=@InstoreID)
set @MaxID = (Select Max(InstoreListID) from Instore_List where InstoreID=@InstoreID)
set @i = @MinID
set @errmsg = ''Begin Transaction tp3
update Instore set InstoreOK=0 where InstoreID=@InstoreID
update Instore_List set InstoreOK=0 where InstoreID=@InstoreID
While @i >=@MinID
BEGIN
select @productID=productID,@number=number,@totalprice=totalprice,@storeID=storeID from Instore_List where InstoreListID = @i
select @psaID=P.PSAID,@pnumber = P.number,@ptotalprice = P.totalprice from Product_Store_All As p where P.productID=@productID and P.storeID = @storeID
IF @pnumber >= @number
Update Product_Store_All set number = @pnumber-@number,totalprice = @ptotalprice-@totalprice from Product_Store_All P where P.PSAID=@psaID
ELSE
BEGIN
RollBack Tran tp3
set @errmsg = '出错的货位'+LTRIM(STR(@storeID))+'产品编号:'+LTRIM(STR(@productID))+'库存产品数量:'+LTRIM(STR(@pnumber))+'撤消产品数量:'+LTRIM(STR(@number))
Break
END
set @i = @i + 1
if @i<=@MaxID
Continue
else
BREAK
END
commit Tran tp3
GO