亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

SQLServer存儲(chǔ)過程中事務(wù)的使用方法

 更新時(shí)間:2015年12月13日 14:53:02   作者:iceKnight  
這篇文章主要介紹了SQLServer存儲(chǔ)過程中事務(wù)的使用方法,簡(jiǎn)短的代碼帶大家更好的學(xué)習(xí)使用SQLServer存儲(chǔ)過程中事務(wù),感興趣的小伙伴們可以參考一下

本文為大家分享了SQLServer存儲(chǔ)過程中事務(wù)的使用方法,具體代碼如下

create proc usp_Stock
@GoodsId int, 
@Number int, 
@StockPrice money, 
@SupplierId int, 
@EmpId int, 
@StockUnit varchar(50), 
@StockDate datetime, 
@TotalMoney money , 
@ActMoney money , 
@baseId int,
@Description nvarchar(255)
as
  declare @error int =0 --事務(wù)中操作的錯(cuò)誤記錄
  --開啟事務(wù)
  begin transaction
    --實(shí)現(xiàn)進(jìn)貨信息的添加
    insert into StockInfo values(@GoodsId, @Number, @StockPrice, @SupplierId, @EmpId, @StockUnit, @StockDate, @TotalMoney, @ActMoney,DEFAULT,@Description, @baseId)
    set @error+=@@ERROR --記錄有可能產(chǎn)生的錯(cuò)誤號(hào)  
    --獲取當(dāng)前進(jìn)貨信息的標(biāo)識(shí)列
    --判斷當(dāng)前商品有沒有進(jìn)貨記錄
    if exists (select * from dbo.InventoryInfo where goodid=@GoodsId) --說明記錄存在,直接修改庫(kù)存數(shù)量
      begin
        update dbo.InventoryInfo set GNumber=GNumber+@Number,TotalMoney+=@TotalMoney where goodid=@GoodsId
        set @error+=@@ERROR --記錄有可能產(chǎn)生的錯(cuò)誤號(hào)      
    end  
    else --這個(gè)商品從來沒有過進(jìn)貨記錄,那么就應(yīng)該添加新的存在信息
      begin
        declare @GWarningNum int --此商品的預(yù)警數(shù)量
        --獲取預(yù)警數(shù)量
        set @GWarningNum=(select WaringNum from dbo.GoodsInfo where GId=@GoodsId)
        insert into   dbo.InventoryInfo values(@GoodsId,@Number,@baseId,@GWarningNum,@TotalMoney,'第一次進(jìn)貨',default)
        set @error+=@@ERROR --記錄有可能產(chǎn)生的錯(cuò)誤號(hào)      
      end
--判斷事務(wù)的提交或者回滾
if(@error<>0)
  begin
    rollback transaction
    return -1 --設(shè)置操作結(jié)果錯(cuò)誤標(biāo)識(shí)
  end
else
  begin
    commit transaction
    return 1 --操作成功的標(biāo)識(shí)
  end
go

希望本文所述對(duì)大家學(xué)習(xí)數(shù)據(jù)庫(kù)操作有所幫助。

相關(guān)文章

最新評(píng)論