日期:2014-05-18 浏览次数:20820 次
create trigger opera on Access instead of insert as begin if exists (select 1 from inserted where mark='取') begin if exists (select 1 from inserted a inner join Depositor b on a.dno = b.dno and a.mark='取' and a.accessnum>b.remainder) begin print '该客户没有足够的金额可取' rollback tran end update Depositor set remainder = remainder - accessnum from Depositor a inner join inserted b on a.dno = b.dno and b.mark='取' end if exists (select 1 from inserted where mark='存' ) begin update Depositor set remainder = remainder + accessnum from Depositor a inner join inserted b on a.dno = b.dno and b.mark='存' end insert into Access select * from inserted end
create trigger opera on Access instead of insert as begin if exists (select 1 from inserted where mark='取') begin if exists (select 1 from inserted a inner join Depositor b on a.dno = b.dno and a.mark='取' and a.accessnum>b.remainder) begin print '该客户没有足够的金额可取' rollback tran end else begin update Depositor set remainder = remainder - accessnum from Depositor a inner join inserted b on a.dno = b.dno and b.mark='取' end end if exists (select 1 from inserted where mark='存' ) begin update Depositor set remainder = remainder + accessnum from Depositor a inner join inserted b on a.dno = b.dno and b.mark='存' end insert into Access select * from inserted end
------解决方案--------------------
create trigger opera on Access instead of insert as begin if exists (select 1 from inserted where mark='取') begin if exists (select 1 from inserted a inner join Depositor b on a.dno = b.dno and a.mark='取' and a.accessnum>b.remainder) begin print '该客户没有足够的金额可取' rollback tran end else begin update Depositor set remainder = remainder - accessnum from Depositor a inner join inserted b on a.dno = b.dno and b.mark='取' end end else if exists (select 1 from inserted where mark='存' ) begin update Depositor set remainder = remainder + accessnum from Depositor a inner join inserted b on a.dno = b.dno and b.mark='存' end insert into Access select * from inserted end try