Is a Trigger appropriate for the following scenario, or do I need to try something else?

We have a situation developing where we need to make use of several non-clustered indexes on several key tables in order to generate reports in a reasonable time frame.  The problem is these are appended bulk-transaction databases which get updated with new records weekly.  There is one data set for each client and we have several, often two to three per server.

Is it effective to use a Trigger to disable and then rebuild the indexes before and then after the INSERT, UPDATE, or DELETE statements are completed?

I may be misunderstanding the principle of a trigger - does the insertion of each row trigger the trigger? Or does it trigger once during the opening of the operation, and then close when the operation completes?
propharmaAsked:
Who is Participating?
 
LowfatspreadCommented:
just on general principles what you are suggesting is not a good idea...
and i would also suggest that it could not be guaranteed to function in future even if it appeared to work now...

how would the dbms work... if you dropped the index it was attempting to use to perform its access with?

the triggers fires each time a "set of rows" is affected....

which depends on the style of the originating sql  and how and where that is processed in the processing... remember that a table can have many triggers specified on it and you have little control over the order in which they are processed... also triggers can be "nested" and called recursively...

a better process is to code the drop and recreate of any indexes around the statement/process you are running... (e.g. a prior and succeeding job steps in a batch job...)  that would also lead to a simpler test and maintainence process.
0
 
JoeNuvoCommented:
the trigger will be fired for each query.

if the query effect only 1 row of the table with trigger, there will be 1 fire of trigger with that 1 row
if the query effect 100 rows of that table, there will be 1 fire of trigger with 100 rows
0
 
sarabhaiCommented:
It depends on the existence of your define triggers type. if they are of type 'for insert' it should be run when  data inserted into table so if you need to disable trigger then first disable trigger and then insert data.
0
 
propharmaAuthor Commented:
So perhaps a stored proceedure that can be executed from any DB then?
0
 
propharmaAuthor Commented:
Very good explanation of the problem as well as an alternate solution to the core issue.  Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.