有两个表,一个订单主表,一个订单明细表
主表A 订单号(orderNo) 数量(Amount) 金额 TotalPrice
明细表B 订单号(orderNo) 数量(Amt) 单价(UnitPrice)
A表中的订单号对应B表中的订单号
当向明细表插入数量时,自动更新主表中的数量和金额!
请各位大虾帮忙!
主表A 订单号(orderNo) 数量(Amount) 金额 TotalPrice
明细表B 订单号(orderNo) 数量(Amt) 单价(UnitPrice)
A表中的订单号对应B表中的订单号
当向明细表插入数量时,自动更新主表中的数量和金额!
请各位大虾帮忙!
解决方案 »
- powerdesigner生成脚本的问题
- 当GROUP BY 与ORDER BY 一起使用时
- 如何在sql中实现类似excel的自定义公式?
- patindex('%,'+rtrim(ID)+',%',','+@ListID+',')>0
- 关于SQL SERVER的版本问题
- 关于时间的问题
- 附加特定的条件怎么写?
- 求一where 条件语句怎么写,我的表有一项为text,我想把文字长度小于10的查询出来,可以不能用LEN,请问用什么?立马给分
- 请问在sql server的存储过程中如何用for循环
- 在自定义函数的内部执行存储过程或exec ?有限制??
- 网络ping 通 但是sql server 2000 不能连接
- 关于cursor的简单问题
update 订单主表 set Amount=Amount+Amt,TotalPrice=TotalPrice+Amt*UnitPrice
from inserted where 订单明细表.orderNo=订单主表.orderNo
create trigger a on 订单明细表 after insert as
update 订单主表 set Amount=Amount+Amt,TotalPrice=TotalPrice+Amt*UnitPrice
from inserted where inserted.orderNo=订单主表.orderNo
create table 订单明细表(orderNo int,Amt int,UnitPrice money)
create table 订单主表(orderNo int,Amount int,TotalPrice money)
insert 订单主表 select 1,5,20
insert 订单主表 select 2,1000,10000
insert 订单明细表 select 1,10,100
select * from 订单明细表
select * from 订单主表
orderNo Amt UnitPrice
----------- ----------- ---------------------
1 10 100.0000(所影响的行数为 1 行)orderNo Amount TotalPrice
----------- ----------- ---------------------
1 15 1020.0000
2 1000 10000.0000(所影响的行数为 2 行)