使用触发器将更改记录到数据库表中 [英] Log changes to database table with trigger

查看:42
本文介绍了使用触发器将更改记录到数据库表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种记录SQL Server 2005数据库中一组特定表上发生的更改的好方法.我相信,做到这一点的最佳方法是通过对更新和删除执行触发器.无论如何,有没有要抓住正在运行的实际语句?一旦有了该语句,我就可以轻松地将其记录在其他地方(其他DB表).但是,我还没有找到一种简单的方法(如果可能的话)来获取正在运行的SQL语句.

I am looking for a good way to log changes that occur on a particular set of tables in my SQL Server 2005 database. I believe the best way to do this is through a trigger that get's executed on updates and deletes. Is there anyway to grab the actual statement that is being ran? Once I have the statement I can easily log it someplace else (other DB table). However, I have not found an easy way (if possible) to grab the SQL statement that is being ran.

推荐答案

触发器很糟糕,我会远离触发器.

Triggers are bad, I'd stay away from triggers.

如果您尝试进行故障排除,请附加 Sql Profiler 具有特定条件的数据库.这将记录每个查询的运行情况,以供您检查.

If you are trying to troubleshoot something, attach Sql Profiler to the database with specific conditions. This will log every query run for your inspection.

另一个选择是更改为调用程序以记录其查询.这是很常见的做法.

Another option is to change to calling program to log its queries. This is a very common practice.

这篇关于使用触发器将更改记录到数据库表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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