请教一个触发器的写法
表结构 id和count两个字段
前台程序会有update语句 update table1 set count = count+1 来修改这个表中的数据
我想做个触发器,如果修改了表中id值为1,2,3这3条纪录的count值,就ROLLBACK TRANSACTION,请问触发器该怎么写?
非常感谢。
------解决方案--------------------create trigger tu_表 on 表
for update
as
if update([count]) and exists(select 1 from inserted i where i.id in (1,2,3))
begin
rollback tran
return
end
------解决方案--------------------Create trigger trgname on 表
for update
as
if (update(count)) and (exists(select * from 表 where id between 1 and 3))
Rollback tran
go
------解决方案--------------------Create trigger trgname on 表
for update
as
if (update(count)) and (exists(select * from Inserted where id between 1 and 3))
Rollback tran
go