一个简单的触发器

create table abcd (id int not null,)

go

create trigger tr_abcd on abcd for insert ,delete,update

as

if exists(select * from inserted where id%2=0)

begin

      roallback

      raiserror 50001 "不允许插入偶数记录!"

      return

end

go

insert into abcd select 1      ----------id=1

insert into abcd select 2      ----------报错:不允许插入偶数记录

请使用浏览器的分享功能分享到微信等