One of my database fields in a table is getting modified by some piece of code. I just can't figure out where!
表中的一个数据库字段正在被某些代码修改。我只是无法弄清楚在哪里!
So, I was wondering if there's a way I can find out.
所以,我想知道我是否有办法找到答案。
I'm using SQL 2008. Can Profiler be used to find out if a particular field is getting updated? How?
我正在使用SQL 2008.可以使用Profiler来查明特定字段是否正在更新?怎么样?
What about a Trigger? If using a trigger (eg. on UPDATE) can you determine what code called it? How can the trigger 'notify me' of this? Email/file?
触发器怎么样?如果使用触发器(例如,在UPDATE上),你可以确定代码叫什么代码吗?触发器怎么能“通知我”这个?电子邮件/文件吗?
3 个解决方案
#1
Yes, an "AFTER UPDATE" trigger on that particular table and field might give you some clues as to when and why the field gets changed.
是的,该特定表和字段上的“AFTER UPDATE”触发器可能会为您提供有关字段何时以及为何更改的一些线索。
From Books Online:
来自联机丛书:
CREATE TRIGGER reminder
ON Person.Address
AFTER UPDATE
AS
IF ( UPDATE (StateProvinceID) OR UPDATE (PostalCode) )
BEGIN
RAISERROR (50009, 16, 10)
END;
GO
A trigger can execute basically any T-SQL code - if you have database mail set up correctly, it could send you an e-mail, yes. Or it can write an audit entry into another table or something like that.
触发器基本上可以执行任何T-SQL代码 - 如果您正确设置了数据库邮件,它可以向您发送电子邮件,是的。或者它可以将审计条目写入另一个表或类似的东西。
EDIT: If you need to find out which statements updated your column, you might be actually better off running a trace on the server, limited to that specific table, and just trace what's happening there. I don't think a trigger can give you that information (which code caused the update to happen).
编辑:如果您需要找出哪些语句更新了您的列,您可能最好在服务器上运行跟踪,仅限于该特定表,并只跟踪那里发生的情况。我不认为触发器可以为您提供该信息(哪些代码导致更新发生)。
Marc
#2
Determining the last Update to or Select against a table (without a trigger!)
确定对表的最后更新或选择(没有触发器!)
#3
Yes, you can use a trigger to execute some code (keep track of who updated the table, email you, etc.) when a table is updated. See this link: Track Updates with a Database Trigger
是的,您可以使用触发器在更新表时执行某些代码(跟踪谁更新了表,通过电子邮件发送给您等)。请参阅此链接:使用数据库触发器跟踪更新
edit: originally posted the wrong link
编辑:最初发布了错误的链接
#1
Yes, an "AFTER UPDATE" trigger on that particular table and field might give you some clues as to when and why the field gets changed.
是的,该特定表和字段上的“AFTER UPDATE”触发器可能会为您提供有关字段何时以及为何更改的一些线索。
From Books Online:
来自联机丛书:
CREATE TRIGGER reminder
ON Person.Address
AFTER UPDATE
AS
IF ( UPDATE (StateProvinceID) OR UPDATE (PostalCode) )
BEGIN
RAISERROR (50009, 16, 10)
END;
GO
A trigger can execute basically any T-SQL code - if you have database mail set up correctly, it could send you an e-mail, yes. Or it can write an audit entry into another table or something like that.
触发器基本上可以执行任何T-SQL代码 - 如果您正确设置了数据库邮件,它可以向您发送电子邮件,是的。或者它可以将审计条目写入另一个表或类似的东西。
EDIT: If you need to find out which statements updated your column, you might be actually better off running a trace on the server, limited to that specific table, and just trace what's happening there. I don't think a trigger can give you that information (which code caused the update to happen).
编辑:如果您需要找出哪些语句更新了您的列,您可能最好在服务器上运行跟踪,仅限于该特定表,并只跟踪那里发生的情况。我不认为触发器可以为您提供该信息(哪些代码导致更新发生)。
Marc
#2
Determining the last Update to or Select against a table (without a trigger!)
确定对表的最后更新或选择(没有触发器!)
#3
Yes, you can use a trigger to execute some code (keep track of who updated the table, email you, etc.) when a table is updated. See this link: Track Updates with a Database Trigger
是的,您可以使用触发器在更新表时执行某些代码(跟踪谁更新了表,通过电子邮件发送给您等)。请参阅此链接:使用数据库触发器跟踪更新
edit: originally posted the wrong link
编辑:最初发布了错误的链接