Sql触发更新表 [英] Sql Trigger to update table

查看:90
本文介绍了Sql触发更新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有StatusMaster表,其列名为status



我想要状态变为'成功'时运行一些实用程序



我认为触发器是最好的解决方案。

所以我想要一个触发器更新,只要状态成功就会触发。



先谢谢。

Hi all,

I have StatusMaster table, which has column called status

I want to run some utility whenever status becomes 'SUCCESS'

I think trigger is the best solution for it.
So i want one trigger on update, which will get triggered whenever status becomes success.

Thanks in Advance.

推荐答案





是的,触发器听起来合适。



这是SQL中触发器的一篇很好的介绍文章。 />


http:// www。 sqlteam.com/article/an-introduction-to-triggers-part-i [ ^ ]


嗨朋友,

希望这会对你有帮助。



Hi Friend,
Hope this will help you.

CREATE trigger TrginsertStatusMaster on StatusMaster
for update
as 
--write the code as per your requirement
--insert INTO emp (name) VALUES ('Satype')





添加的代码块[/ edit]



[edit]Code block added[/edit]


create trigger trgafterupdate on dbo.Employee_Test
for update
as declare @emp_id int;
 declare @emp_name nvarchar(50);
 declare @emp_sal decimal(10,2);
 declare @status nvarchar(50);

 select @status=i.status from inserted i;

 if(@status='SUCCESS')
 begin
  print 'abc';//on true condition  code here 
  end
  else
  print 'andd';// on false condition code here





在触发器主体中,已经使用了名为inserted的表。这个表是一个逻辑表,包含已更新的行



代码块已修复[/ edit]



In trigger body ,table named inserted has been used .this table is a logical table and contains the row that has been updated

[edit]Code block fixed[/edit]


这篇关于Sql触发更新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆