在sql中更新后触发 [英] Trigger after update in sql
本文介绍了在sql中更新后触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果mt_processed已更新,我的目标是将数据复制到另一个表!这个触发器工作但是:1-i需要使用另一种方法改进它2我需要补充一点,如果mt_processed更新为10我需要将数据插入某个表,如果它被更新为1我需要将数据插入另一个表格..
i有以下触发器:
ALTER 触发器 afterUpdateProcessed
on MT_PROCESS
update as 开始 声明 var 选择 data = var insert var
i感谢您的帮助:)
解决方案
是触发肯定会帮助你在这种情况下,你必须定义tr在你的桌子上igger,然后你需要使用Inserted和delete逻辑表来查看更新的数据,或者你可以从这个表中获得旧的和新的两种类型的值,从这个值你可以决定你要插入的操作表,希望这对你有帮助。
你可以参考这篇文章
http://www.dotnet-tricks.com/Tutorial/ sqlserver / 7OT8250912-Inserted,-Deleted-Logical-table-in-SQL-Server.html
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/0ccec191-d161-4054-a81c-28dba1bcde85/audit-trigger-using-inserted-and-deleted-tables
问候,
Mubin
my target is to copy the data to another table if the mt_processed is updated ! this trigger is working but: 1-i need to improve it using another method 2- i need to add that if the mt_processed was updated to 10 i need to insert the data to a certain table and if it was updated to 1 i need to insert the data to a different table ..
i have the following trigger :
ALTER trigger afterUpdateProcessed on MT_PROCESS for update as begin declare var select data=var insert var
i appreciate your help :)解决方案Hi,
Yes Trigger will surely help you in this scenario, you have to define trigger on your table and then you need to use Inserted and delete logical Table to view which data is updated or you can get both type of values old and new from this tables and from that value you can decide your operation you want to insert in which table , hope this will help you.
You can refer this article
http://www.dotnet-tricks.com/Tutorial/sqlserver/7OT8250912-Inserted,-Deleted-Logical-table-in-SQL-Server.html
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/0ccec191-d161-4054-a81c-28dba1bcde85/audit-trigger-using-inserted-and-deleted-tables
Regards,
Mubin
这篇关于在sql中更新后触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文