日期:2014-05-18 浏览次数:20684 次
create trigger xxx on a for insert as declare @age int select @age = age from insertd a begin if @age < 20 begin insert into b select * from a where a.id = inserted.id end else begin if @age >= 20 and @age < 30 begin insert into c select * from a where a.id = inserted.id end else begin insert into d select * from a where a.id = inserted.id end end end
------解决方案--------------------
create trigger xxx on t1 for insert as begin declare @age int select @age = age from inserted if @age<20 insert into b select * from inserted else if (@age>20 and @age<30) insert into c select * from inserted else if @age>30 insert into d select * from inserted end
------解决方案--------------------
create trigger xxx on a for insert as begin insert into b select * from a where a.id = inserted.id and age <20 insert into c select * from a where a.id = inserted.id and age >= 20 and age <30 insert into d select * from a where a.id = inserted.id and age >= 30 end
------解决方案--------------------
2楼的是有问题的,如果一次插入多条,age不同段,就会出现插错表的现象