国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > SQL Server > 正文

SQLServer存儲過程中事務的使用方法

2020-07-25 12:48:15
字體:
來源:轉載
供稿:網友

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

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 --事務中操作的錯誤記錄  --開啟事務  begin transaction    --實現進貨信息的添加    insert into StockInfo values(@GoodsId, @Number, @StockPrice, @SupplierId, @EmpId, @StockUnit, @StockDate, @TotalMoney, @ActMoney,DEFAULT,@Description, @baseId)    set @error+=@@ERROR --記錄有可能產生的錯誤號      --獲取當前進貨信息的標識列    --判斷當前商品有沒有進貨記錄    if exists (select * from dbo.InventoryInfo where goodid=@GoodsId) --說明記錄存在,直接修改庫存數量      begin        update dbo.InventoryInfo set GNumber=GNumber+@Number,TotalMoney+=@TotalMoney where goodid=@GoodsId        set @error+=@@ERROR --記錄有可能產生的錯誤號          end      else --這個商品從來沒有過進貨記錄,那么就應該添加新的存在信息      begin        declare @GWarningNum int --此商品的預警數量        --獲取預警數量        set @GWarningNum=(select WaringNum from dbo.GoodsInfo where GId=@GoodsId)        insert into   dbo.InventoryInfo values(@GoodsId,@Number,@baseId,@GWarningNum,@TotalMoney,'第一次進貨',default)        set @error+=@@ERROR --記錄有可能產生的錯誤號            end--判斷事務的提交或者回滾if(@error<>0)  begin    rollback transaction    return -1 --設置操作結果錯誤標識  endelse  begin    commit transaction    return 1 --操作成功的標識  endgo

希望本文所述對大家學習數據庫操作有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 绥滨县| 辛集市| 津市市| 故城县| 资源县| 延川县| 慈溪市| 冷水江市| 黔江区| 泰安市| 平南县| 平乡县| 绵竹市| 裕民县| 桐乡市| 安福县| 诸暨市| 宁武县| 吴川市| 建湖县| 娄烦县| 香格里拉县| 衡东县| 太白县| 松原市| 安乡县| 黎川县| 太仓市| 平邑县| 五大连池市| 宾阳县| 榆社县| 泰和县| 邛崃市| 西和县| 正镶白旗| 辉南县| 南皮县| 林州市| 万源市| 井陉县|