日期:2014-05-18 浏览次数:20619 次
create trigger tr_name on A for insert as begin if exists(select 1 from inserted where content like '%A%') rollback end
------解决方案--------------------
if object_id('a') is not null drop table a go create table a ( id int, content varchar(10) ) go if object_id('tr_a_insert') is not null drop trigger tr_a_insert go create trigger tr_a_insert on a for insert as if exists(select 1 from inserted where content like '%abc%') rollback go insert into a select 1,'123' insert into a select 2,'6abc6' select * from a /* id content ----------- ---------- 1 123 (1 行受影响) */
------解决方案--------------------
一起执行肯定是不行的,相当一个批处理,出错的地方就停止了
------解决方案--------------------
create trigger test on a for insert as if exists(select 1 from inserted where content like '%abc%') rollback else insert into a(content) select @content go