当前位置: 代码迷 >> Sql Server >> SQlSERVER 2000中触发器的简单有关问题,帮帮小弟吧
  详细解决方案

SQlSERVER 2000中触发器的简单有关问题,帮帮小弟吧

热度:100   发布时间:2016-04-27 19:04:02.0
SQlSERVER 2000中触发器的简单问题,帮帮小弟吧

问题描述:有一张表test   现在要求在该表上创建一触发器,触发器要实现以下功能  

当该表上的C1列中某一行的数值发生UPDATE操作之后,将该数值自动+100后更新回去,其他行的C1值不受影响

(如果该表没有主键,该如何写?如果有主键列为KEY,又该如何写呢?)


------解决方案--------------------
create trigger tu_test on test
for update
as
if update(c1) and exists(select 1 from inserted i,deleted d where i.主键=d.主键 and isnull(i.c1,0) <> isnull(d.c1,0))
begin
update test
set c1=i.c1+100
from test,i,d
where test.主键=i.主键 and i.主键=d.主键 and isnull(i.c1,0) <> isnull(d.c1,0)
end
  相关解决方案