473,396 Members | 1,893 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,396 software developers and data experts.

Trigger Problems


I have an Insert, Update and delete trigger on a table that works fine.
It records the changes into another table called tblTracking.
tblTracking records the changes so they can be uploaded to another
server off site. The problem is that it fires each time my DTS package
fires (every 15 minutes). The DTS package imports data from an ODBC
database then compares what is in the source/destination table with a
Insert Into, select not in (for new records) and Update statements for
changed records.

My tblTracking gets pretty big by mid day and doesn't tell the clear
picture of what has really changed or been added with all the update and
inserts flying around. I can't define this original ODBC data source as
a linked server. Any suggestions on how I can make this more efficient.
Thanks
Steve

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
4 6283

"Steve Bishop" <st****@viper.com> wrote in message
news:40***********************@news.frii.net...

I have an Insert, Update and delete trigger on a table that works fine.
It records the changes into another table called tblTracking.
tblTracking records the changes so they can be uploaded to another
server off site. The problem is that it fires each time my DTS package
fires (every 15 minutes). The DTS package imports data from an ODBC
database then compares what is in the source/destination table with a
Insert Into, select not in (for new records) and Update statements for
changed records.

My tblTracking gets pretty big by mid day and doesn't tell the clear
picture of what has really changed or been added with all the update and
inserts flying around. I can't define this original ODBC data source as
a linked server. Any suggestions on how I can make this more efficient.
Thanks
Steve

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


It's not clear from your post what the DTS package is doing, and what your
issue with the trigger is. Are you asking how to prevent a DTS package
firing a trigger? If so, then checking 'Use Fast Load' in a Transform Data
Task means that triggers won't fire. Or ALTER TABLE can disable the trigger
temporarily, but that may not be acceptable as it wouldn't fire at all while
the package is running.

If this doesn't help, perhaps you could clarify what the DTS package is
doing, as well as where in the sequence of events the trigger is fired.

Simon
Jul 20 '05 #2
Hi

Sounds like your trigger is working well!

If you disable it then you would have to stop all other users changing the
data in the table to make sure that your audit data was compete (apart from
DTS information!). If your DTS package is being run on the server it may be
possible to use HOST_NAME() or USER_NAME() as a filter. If you make your
trigger insert audit data conditionally on these it will leave a rather
large whole in your auditing, but if you included it in the audit table then
you could filter your queries and still have all the data available.

John

"Steve Bishop" <st****@viper.com> wrote in message
news:40***********************@news.frii.net...

I have an Insert, Update and delete trigger on a table that works fine.
It records the changes into another table called tblTracking.
tblTracking records the changes so they can be uploaded to another
server off site. The problem is that it fires each time my DTS package
fires (every 15 minutes). The DTS package imports data from an ODBC
database then compares what is in the source/destination table with a
Insert Into, select not in (for new records) and Update statements for
changed records.

My tblTracking gets pretty big by mid day and doesn't tell the clear
picture of what has really changed or been added with all the update and
inserts flying around. I can't define this original ODBC data source as
a linked server. Any suggestions on how I can make this more efficient.
Thanks
Steve

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 20 '05 #3

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.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4
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
Jul 20 '05 #5

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

Similar topics

2
by: Galina | last post by:
Hello I work with Oracle 9 database. I want to create a trigger using 2 tables: KEY_SKILLS_STUDENT and KEY_SKILLS. There are fields in KEY_SKILLS_STUDENT: KEY_SKILLS_ID, PORTFOLIO_RESULT and...
9
by: Lauren Quantrell | last post by:
Is there a way to create a text file (such as a Windows Notepad file) by using a trigger on a table? What I want to do is to send a row of information to a table where the table: tblFileData has...
4
by: Marie-Christine | last post by:
i want to audit transactions done to table TOrig. I created table TAudit same as TOrig in addition to ActionID (1 for insert, 2 for update, 3 for delete), System Date and System User. I created...
0
by: Marko Damaschke | last post by:
Hello alltogether, i'm working on a database-plattform which should work with fail-over-technics. Therefor 2 identic machines with internal RAID are available, which work in...
9
by: Martin | last post by:
Hello, I'm new with triggers and I can not find any good example on how to do the following: I have two tables WO and PM with the following fields: WO.WONUM, VARCHAR(10) WO.PMNUM,...
33
by: coosa | last post by:
I have a table: ---------------------------------------------------- CREATE TABLE CATEGORY ( CATEGORY_ID INTEGER IDENTITY(1,1) NOT NULL, CATEGORY_NAME VARCHAR(40) NOT NULL,...
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: Prem via DBMonster.com | last post by:
hi, i am working on a migration project from Oracle to db2 8.1. i was able to migrate the stored procedures and functions in oracle to db2 with the help of the migration tool kit. now finally...
12
by: Bob Stearns | last post by:
I am trying to create a duplicate prevention trigger: CREATE TRIGGER is3.ard_u_unique BEFORE UPDATE OF act_recov_date ON is3.flushes REFERENCING NEW AS N FOR EACH ROW MODE DB2SQL WHEN...
7
by: Shane | last post by:
I have been instructed to write a trigger that effectively acts as a foreign key. The point (I think) is to get me used to writing triggers that dont use the primary key(s) I have created the...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.