仅在修改列时才触发SQL更新 [英] SQL update trigger only when column is modified

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

问题描述

需要修改所有具有审计配置的表中的所有触发器。如果ModifiedBy为空或NULL,那么我们需要使用下面的SQL命令来获取当前用户名并填写ModifiedBy列。基本上我们要做的是确保当某人填写modifiedby和modified date时使用SQL Maintenance studio更新记录。所以我们希望触发器检查记录的修改者是否被更新(不要与你写入审计表的记录混淆),如果它是空的,我们需要选择system_user和当前的日期和时间并更新表。

I need to modify all the triggers in all the tables which have audit configuration. If the ModifiedBy is empty or NULL then we need to use the below SQL Command to get the Current User Name and fill in the ModifiedBy Column.Basically what we are trying to do Is to make sure the modifiedby and modified date get filled in when someone updates a record using SQL Maintenance studio. So we want the trigger to check if the modified by of the record being updated (not to be confused with the record you write to the audit table) and if it is empty we need to select the system_user and the current date and time and update the table.

推荐答案

您好,



您可以使用 EvenData 生成对于DDL触发器中的此更改事件,并将其用于自己桌面上的更新。



本文将帮助您朝这个方向发展..



你可以知道表,数据库,表(对象名),用户等。



发送有关SQL Server中数据库架构更改的电子邮件警报 [ ^ ]



你需要在ste中使用更新查询第4页,使用偶数时间和登录名更新相应的表格。



希望这对您有帮助。



问候。
Hi,

You can use EvenData generated for this alteration event in DDL trigger and use it for updation on your own table.

This Article will help you in this direction..

You can know table ,database ,Table(object name),User etc.

Send Email Alert on Database Schema Change in SQL Server[^]

You need to just use update query in step 4 , to update appropriate tables with eventime and loginname.

Hope this will help you.

Regards.


访问这里......



http://www.sqlservercentral.com/Forums/Topic750337-145-1.aspx [ ^ ]
visit here...

http://www.sqlservercentral.com/Forums/Topic750337-145-1.aspx[^]


这篇关于仅在修改列时才触发SQL更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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