update的触发器怎么写啊

liquidcn 2011-01-27 04:48:02
表1:

id c1 c2
1 a 0
2 a 0
3 b 0
4 c 0
5 a 0


我现在想写一个触发器:当表1里有数据更新(这个更新肯定为单条数据更新的),且这条数据的c1为a,c2从0变为1了

类似:

create.....

if (这条数据的c1=a AND c2=0)
其它操作....

关键就是这条件怎么写
...全文
117 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
叶子 2011-01-27
  • 打赏
  • 举报
回复
水哥正解。

不知道这样是不是也可以。

create trigger trigger_name on tablename
for update
as
begin
if((select c1 from inserted)='a' and (select c2 from inserted)=0)
update tablename set c2=1
end
蜘蛛上网 2011-01-27
  • 打赏
  • 举报
回复
楼上正解
水族杰纶 2011-01-27
  • 打赏
  • 举报
回复
--try
create trigger tri_name on t1
for update
as
update t1
set c2=1
from inserted i,t1
where i.id=t.id and i.c1='a' and i.c2=0

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧