日期:2014-05-18 浏览次数:20461 次
if object_id('a','U') is not null drop table a go create table a ( id int, m int ) go insert into a select 1,2 union all select 2,0 go if object_id('b','u') is not null drop table b go create table b ( id int, c varchar(10) ) go insert into b select 1,'11' union all select 2,'22' go if object_id('tr_b','tr') is not null drop trigger tr_b go create trigger tr_b on b for update as if not exists(select 1 from a inner join inserted on a.id=inserted.id and a.m=0) rollback go update b set c='111' where id=1 --A表中id为1的m不等于0,终止更新 go update b set c='222' where id=2 --A表中id为2的m等于0,继续更新 go select * from b --可以看到第一条更新未执行,第二条更新执行成功 /* id c ----------- ---------- 1 11 2 222 (2 行受影响) */