473,386 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Update trigger or ?

Hello,

I've a problem where some data gets updated but I don't know which
process (SP) is responsible for it (it's an old installation which I've
taken over).
Is it somehow possible to know which process/user/SP performs an update
on a special table/column?
I was thinking about to implement an update trigger but unfortunately
I've no idea how to figure out the "parent process" which was
responsible for the update.

I'm using MS SQL Server 2000.
Thanks Joerg

Apr 23 '07 #1
4 3868
On 23 Apr, 11:25, Joerg Gempe <j_spam_filter_ge...@gmx.dewrote:
Hello,

I've a problem where some data gets updated but I don't know which
process (SP) is responsible for it (it's an old installation which I've
taken over).
Is it somehow possible to know which process/user/SP performs an update
on a special table/column?
I was thinking about to implement an update trigger but unfortunately
I've no idea how to figure out the "parent process" which was
responsible for the update.

I'm using MS SQL Server 2000.

Thanks Joerg

Apr 23 '07 #2
Joerg Gempe (j_*****************@gmx.de) writes:
I've a problem where some data gets updated but I don't know which
process (SP) is responsible for it (it's an old installation which I've
taken over).
Is it somehow possible to know which process/user/SP performs an update
on a special table/column?
This query:

SELECT o.name, o2.name, c.name
FROM sysobjects o
JOIN sysdepends d ON o.id = d.id
JOIN sysobjects o2 ON d.depid = o2.id
JOIN syscolumns c ON d.depid = c.id
AND d.depnumber = c.colid
WHERE o2.name = 'yourtbl'
AND c.name = 'yourcol'
AND d.resultobj = 1

may return the information you need. I say may, because the dependency
information in a database is rarely complete. This is because if you
drop and recreate a table, without reloading the stored procedures,
the depencies are lost.

If it's possible for you to build the database from scripts, and
making sure that procedures and triggers are built after all tables,
then your odds are better.
I was thinking about to implement an update trigger but unfortunately
I've no idea how to figure out the "parent process" which was
responsible for the update.
DBCC INPUTBUFFER could address this, but:

1) it requires the user to have sysadm privileges.
2) it will only show you the command sent from the client. If procedures
nest in several levels, this information may not be sufficient.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Apr 23 '07 #3
Erland Sommarskog wrote:
This query:

SELECT o.name, o2.name, c.name
FROM sysobjects o
JOIN sysdepends d ON o.id = d.id
JOIN sysobjects o2 ON d.depid = o2.id
JOIN syscolumns c ON d.depid = c.id
AND d.depnumber = c.colid
WHERE o2.name = 'yourtbl'
AND c.name = 'yourcol'
AND d.resultobj = 1
Hello,

Thanks for this, this already helps a little bit and I know now all the
SPs, but it is unfortunately not 100% what I'm was looking for.

I want to know at runtime who or what changes a value in a specific
table,column,row.
Problem is that it might not only a SP but a plain SQL statement or
another trigger or ... ?

I want to create an Update trigger to capture the old value, the new
value and which process/user/sql command performed the update.
So roughly spoken I'm looking for something like:

create trigger getCaller
on MyTable
for update
as
--- problem how to figure out the caller who's responsible that the
trigger is called
select @caller = .?.?.?.
---
insert into MyCallerTable select @caller, getdate(), * from deleted,
inserted
....
Where @caller should give me as much information as possible about the
process which "runs" the trigger.

Thank you
Joerg

Apr 25 '07 #4
Joerg Gempe (j_*****************@gmx.de) writes:
I want to know at runtime who or what changes a value in a specific
table,column,row.
Problem is that it might not only a SP but a plain SQL statement or
another trigger or ... ?
Triggers are not a problem. They are captured by the above.

If you have applications emitting loose SQL statements without stored
procedures, you now see one reason why you should not have this. I guess
you will have to first search the code for the table name, and then
weed out the UPDATE statements.
I want to create an Update trigger to capture the old value, the new
value and which process/user/sql command performed the update.
So roughly spoken I'm looking for something like:

create trigger getCaller
on MyTable
for update
as
--- problem how to figure out the caller who's responsible that the
trigger is called
select @caller = .?.?.?.
---
insert into MyCallerTable select @caller, getdate(), * from deleted,
inserted
...
As I said, to do this at run-time DBCC INPUTBUFFER is your only option. But
it will only work if the caller has sysadm privileges. And it's not going to
help the throughput of the application.

It's an uphill battle, I'm afraid.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Apr 25 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Jason | last post by:
I have a table that matches up Securities and Exchanges. Individual securities can belong on multiple exchanges. One of the columns, named PrimaryExchangeFlag, indicates if a particular exchange is...
1
by: Gent | last post by:
am using FOR UPDATE triggers to audit a table that has 67 fields. My problem is that this slows down the system significantly. I have narrowed down the problem to the size (Lines of code) that need...
1
by: shottarum | last post by:
I currently have 2 tables as follows: CREATE TABLE . ( mhan8 int, mhac02 varchar(5), mhmot varchar(5), mhupmj int )
3
by: takilroy | last post by:
Hi, Does anyone know of a simple way to do this? I want to create an insert trigger for a table and if the record already exists based on some criteria, I want to update the table with the...
1
by: Simon Holmes | last post by:
Hi, I am having trouble calling a UDF from a 'before update' trigger whereas I have no problems calling it from the 'after update' trigger. The trigger is as below : CREATE TRIGGER foo NO...
18
by: Bill Smith | last post by:
The initial row is inserted with the colPartNum column containing a valid LIKE pattern, such as (without the single quotes) 'AB%DE'. I want to update the column value with the results of a query...
2
by: D. Dante Lorenso | last post by:
I'm trying to build a table that will store a history of records by enumerating the records. I want the newest record to always be number ZERO, so I created a trigger on my table to handle the...
5
by: wpellett | last post by:
I can not get the SQL compiler to rewrite my SQL UPDATE statement to include columns being SET in a Stored Procedure being called from a BEFORE UPDATE trigger. Example: create table...
1
by: abhi81 | last post by:
Hello All, I have a table on which I have created a insert,Update and a Delete trigger. All these triggers write a entry to another audit table with the unique key for each table and the timestamp....
13
by: Neil | last post by:
I'm running an update query in SQL 7 from QA, and it runs forever. Has been running for 20 minutes so far! The query is quite simple: update a single field in a table, based on a join with another...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.