这个触发器怎么实现呢
做更新操作的时候,假如字段 num 更新为2 就往另一个表 change里面插入这条更新后的数据。如果num更新为3就把更新前的数据和更新后的数据都插入到change里面,而且字段num都是3.change 里面也有num字段。
[最优解释]
create trigger t1
on tb
for update
as
begin
if exists(select 1 from inserted where num=2)
insert into change
select * from change
else exists(select 1 from inserted where num=3)
insert into change
select * from inserted
union
select * from deleted --插入式把num列的值改为3
end
create trigger t1
on tb
for update
as
begin
if update (num)
begin
if exists(select 1 from inserted where num=2)
insert into change
select * from inserted
where num = 2
if exists(select 1 from inserted where num=3)
insert into change
select * from inserted
where num = 3
union all
select d.col1,d.col2,num=3,d.col4... from deleted d,inserted i
where i.key = d.key
and i.num = 3
end
end