如有下面的表
create table test
(
autoid int identity(1,1) primary key not null,
Ca varchar(20) not null,
Cb varchar(20) not null,
qty decimal(18,2) not null,
money decimal(18,2) not null
)
insert into test(ca,cb,qty,money) values('a001','b001',20,20)
insert into test(ca,cb,qty,money) values('a003','b01',20,20) --这行作测试
insert into test(ca,cb,qty,money) values('a005','b02',2,20.2)
insert into test(ca,cb,qty,money) values('a002','b021',1.2,20.3)
我想写一个插入与更新触发器,条件是当CA='a003' and CB='b01' and qty=0时,让这行的money也为0 ,行是没有重复值
create table test
(
autoid int identity(1,1) primary key not null,
Ca varchar(20) not null,
Cb varchar(20) not null,
qty decimal(18,2) not null,
money decimal(18,2) not null
)
insert into test(ca,cb,qty,money) values('a001','b001',20,20)
insert into test(ca,cb,qty,money) values('a003','b01',20,20) --这行作测试
insert into test(ca,cb,qty,money) values('a005','b02',2,20.2)
insert into test(ca,cb,qty,money) values('a002','b021',1.2,20.3)
我想写一个插入与更新触发器,条件是当CA='a003' and CB='b01' and qty=0时,让这行的money也为0 ,行是没有重复值
on test
after insert
as
begin
declare @id int
set @id=@@identity
update test set money=0 where sutoid=@id
end