表一:
ID 预设备材料费
1 100.00
2 200.00
3 150.00
表二:
ID 设备材料费
1 100.00
2 200.00
3 150.00
实现目的:我想把表一中的数据预估设备材料费初始时保存到表二的设备材料费中,而表二的设备材料费修改后不一定等于表一的预估设备材料费。我现在做的表二的数据修改后,表一的数据也修改了。
大家帮看看啊,先谢谢了。
ID 预设备材料费
1 100.00
2 200.00
3 150.00
表二:
ID 设备材料费
1 100.00
2 200.00
3 150.00
实现目的:我想把表一中的数据预估设备材料费初始时保存到表二的设备材料费中,而表二的设备材料费修改后不一定等于表一的预估设备材料费。我现在做的表二的数据修改后,表一的数据也修改了。
大家帮看看啊,先谢谢了。
create trigger tri_A
on 表一
for insert,update
as
begin
update 表二 set 设备材料费=b.预设备材料费 from 表二 a,inserted b where a.id=b.id
end
再问个问题:
我在表一中创建了触发器,可动行时表一中的预估设备材料费并没填写到表二的设备材料费中啊,请问是否还需要写什么设置吗?
gocreate table b(ID int,预设备材料费 dec(10,2))
go
create trigger tri_A
on a
for insert,update
as if @@rowcount=0 return
if exists(select 1 from a,b where a.id=b.id)
update b set b.预设备材料费=a.预设备材料费 from inserted a,b where a.id=b.id
else
insert into b select * from inserted
goinsert into a select 1,100.00
union all select 2,200.00
union all select 3,150.00
goselect * from a
select * from bupdate a set 预设备材料费=1 where id=1
select * from a
select * from bdrop trigger tri_A
drop table a,b--这样?
请问:if @@rowcount=0 return是什么意思
返回受上一语句影响的行数。如果@@ROWCOUNT=0就直接跳出触发器了