Groups | Blog | Home
all groups > sql server (alternate) > february 2006 >

sql server (alternate) : Capturing Mysterious Truncation/deletion of a table


coolnoff NO[at]SPAM hotmail.com
2/14/2006 11:22:25 AM
I have a dts which creates a table which is utilized on my local
intranet. The DTS runs without error and the table is
created/populated/transfered to the appropriate db. Then it appears
that there is an action on this table which truncates it. I have been
unable to determine the culprit. Can I create a trigger that will
capture truncation? I have tried to create a trigger to capture this
information but none that I attempt seem to work on capturing a
truncation or a drop table and re-create.

Any help would be greatly appreciated.

MT.
Erland Sommarskog
2/14/2006 10:42:26 PM
(coolnoff@hotmail.com) writes:
[quoted text, click to view]

You can add a trigger FOR DELETE on the table, that will capture the
the truncation happens through DELETE.

However, the trigger will not catch if the table is emptied by
TRUNCATE TABLE or DROP TABLE + ALTER TABLE. One way you can handle
this is to add a table that has a foreign key referencing this table.
This will cause TRUNCATE TABLE and DROP TABLE to fail.

Have you examined the possibility that the reason the data disappears
is because there is a transaction that is not committed, so the
population of the table is simply rolled back?

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
Hugo Kornelis
2/14/2006 11:24:52 PM
[quoted text, click to view]

Hi MT,

In SQL Server 2000, there is no way to monitor either truncation or
dropping of a table using triggers. You'll have to use Profiler to find
out who/what is destorying your data.

--
AddThis Social Bookmark Button