商品信息表(id,classid....)
商品库存信息表(id,classid,goodsnum)
商品入库表(id,num)
添加入库表时,如果库存信息表里有此商品id就让goodsnum=goodsnum+num 如果没有就进行插入操作。
--商品信息表
Create Table GoodsInfo(Id Int,ClassId Int)
Insert GoodsInfo Select 1,3
Union all Select 2,3
Union all Select 3,3
--商品库存信息表
Create Table StockInfo(Id Int,ClassId Int)
Insert StockInfo Select 1,2,3
Union all Select 2,3,5
--入库表
Create Table StockIn(Id Int,Num Int)
--建立触发器
Create Trigger Tri_StockIn
On StockIn
Instead Of Insert
As
If Not Exists(Select 1 From Inserted A ,StockInfo B Where A.id=B.id )
Insert StockInfo(id,GoodsNum) Select * From Inserted
Else
Update A
Set GoodsNum=GoodsNum+B.Num
From StockInfo A,Inserted B
Where A.id=B.id
Update A
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余1页未读,立即下载