Steve Bishop (st****@viper.com) writes:
DTS package steps:
1. Empty imported ODBC tables.
2. Re-import ODBC tables.
3. Insert Into (Select ...Not In) fires between a view of the imported
odbc tables and the destination table.
4. Update query fires between view of the imported odbc tables and the
destination table.
5. Some other queries fire that I have selectivity over so they don't
hit every row.
I think my main problem is coming from the update query. The update
trigger on the destination table makes an entry for every row in the
table. It would be cool if it just looked at the records that have
changed. Maybe it's because my trigger has syntax like:
IF EXISTS (SELECT * FROM INSERTED)
BEGIN
My insert statement....
Help appreciated. Thanks.
The trigger does not know which rows that have changed. To that end
you can compare the inserted table to the deleted table:
IF EXISTS (SELECT *
FROM inserted i
JOIN deleted d ON i.keycol = d.keycol
WHERE i.col1 <> d.col1 OR
i.col2 <> d.col2 ...
But involving both inserted and deleted in a query may be expensive.
It may be cheaper to declare two table variables and inserted into
these the data from inserted/deleted.
If you simply want the trigger to not bother about DTS at all, you
can create a temp table from DTS, call it #DTS$loading. Then in the
trigger, you do this:
IF object_id('tempdb..#DTS$loading') IS NULL
BEGIN
-- Do auditing.
Note here that how the table looks like is irrelevant, the mere existence
of a table acts as a flag. The advantage with this over ALTER TABLE
DISABLE TRIGGER is that you don't miss auditing of other users playing
around while the load is running.
--
Erland Sommarskog, SQL Server MVP,
so****@algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp