首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

请问一个触发器的写法

2012-02-05 
请教一个触发器的写法表结构id和count两个字段前台程序会有update语句updatetable1setcountcount+1来修改

请教一个触发器的写法
表结构   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

热点排行
Bad Request.