如果pid和cartname可以唯一标志一行,try:CREATE TRIGGER cart ON shoppingcart
instead of INSERT
AS
update shoppingcart
set quantity=isnull(quantity,0)+I.quantity
from shoppingcart T
join inserted I on I.pid=T.pid and I.cartname=T.cartname
go
instead of INSERT
AS
update shoppingcart
set quantity=isnull(quantity,0)+I.quantity
from shoppingcart T
join inserted I on I.pid=T.pid and I.cartname=T.cartname
go
解决方案 »
- 如何在移动设备上安装sql mobile数据库,使之能订阅sql2005发布的数据库?
- 求解一条SQL语句写法
- reportviewer 打印問題
- 求教,SQL2008R2数据库附加时候提示偏移量错误
- 两台用无线上网连接的机子间怎么访问对方的SQL SERVER数据库
- 求一句sql
- SQL存储过程异常情况
- 请教一条SQL语句
- 忘了说明是Access里,不是Sql Server:某条记录的两列求合计的问题,简单的sql语句求教!!
- 【关于使用sql生成五位字母+数字自增的编号】速结帖
- 为什么我的SQLSERVER企业版装好了,但是不能TELNET 127.0.0.1 1433端口
- SQL SERVER 安装遇到的问题,请指点
instead of INSERT
AS
if exists(select 1 from shoppingcart as t1 join inserted as t2
on t1.pid=t2.pid and t1.cartname=t2.cartname)
begin
update shoppingcart
set quantity=quantity+i.quantity
from inserted as i join shoppingcart as tt
on i.pid=tt.pid and i.cartname=tt.cartname
end
else
begin
insert into shoppingcart(pid,cartname,quantity)
select pid,cartname,quantity from inserted
end
go
instead of INSERT
AS
update shoppingcart
set quantity=quantity+i.quantity
from inserted as i join shoppingcart as tt
on i.pid=tt.pid and i.cartname=tt.cartname --没有处理pid或cartname为null的情况
insert into shoppingcart(pid,cartname,quantity)
select i.pid,i.cartname,i.quantity
from inserted as i join shoppingcart as tt
where i.pid<>tt.pid or i.cartname<>tt.cartname
go