34,593
社区成员
发帖
与我相关
我的任务
分享
--设表名为tt
create trigger trigIU_tt on tt
for insert
as
update a
set c=case when a=b when 1 else 2 end
from tt a,inserted b
where a.a=b.a and a.b=b.b
--创建测试表
create table tt(a int,b int,c as case when a=b then 1 else 2 end)
insert into tt
select 1,3
union all select 2,2
union all select 5,3
union all select 6,6
union all select 9,9
union all select 2,3
--查询
select * from tt
--结果
/*
a b c
----------- ----------- -----------
1 3 2
2 2 1
5 3 2
6 6 1
9 9 1
2 3 2
(所影响的行数为 6 行)
*/
--删除测试表
drop table tt