eg:
CREATE TRIGGER DeleteCode ON [dbo].[StandardCode] 
FOR DELETE 
AS 
if (select count(*) from deleted )>1
begin
raiserror('警告!删除记录有多条!',16,1)
rollback transaction
end

解决方案 »

  1.   


    CREATE TRIGGER DeleteCode ON [dbo].[StandardCode] 
    FOR DELETE 
    AS 
    if (select count(*) from deleted )>1
    begin
    raiserror('警告!删除记录有多条!',16,1)
    rollback transaction
    end
      

  2.   

    我做一个销存中的取消产品审核的例子:Create Procedure PCheckOutstore @InstoreID int,@errmsg varchar(200) output,@MinID int = 0,@MaxID int = 0,@i int = 0,@number int = 0,@totalprice int = 0,@productID int = 0,@storeID int = 0,@pnumber int = 0,@ptotalprice money = 0,@psaID int =0
    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
      

  3.   

    回滚就是取消的意思在sql server中用 rollback tran
      

  4.   

    create trigger on ... for...  我记得只有instead of 和 after格式呀!!!