一个表更新,触发器实现另一个表的更新
我两张表,表1是员工薪资表,里面有字段 员工号,员工工资,表2是员工税表,里面的字段是员工号,个税,
当向表1中插入记录时,同时向表人中插入记录,个税计算方法为 工资 <1000,不交税,1000-5000 交1%,5000以上交3%
------解决方案--------------------create trigger triT
on [Table1]
for insert
as
insert [Table2] select 员工号,case when 员工工资 <1000 then 0
when 员工工资> =1000 and 员工工资 <5000 then 员工工资*0.01
else
员工工资*0.03
end
from inserted
------解决方案--------------------create trigger trig_name on 表1
for insert
as
insert 表2(员工号,个税)
select 员工号,
case when 员工工资 <1000 then 0
when 员工工资 between 1000 and 5000 then 员工工资*0.01
when 员工工资> 5000 then 员工工资*0.03
end 个税
from inserted
go