Solved

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

Posted on 2011-03-18
5
226 Views
Last Modified: 2012-05-11
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?
0
Comment
Question by:propharma
5 Comments
 
LVL 11

Expert Comment

by:JoeNuvo
ID: 35170311
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
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 500 total points
ID: 35171358
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
 
LVL 9

Expert Comment

by:sarabhai
ID: 35171611
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
 

Author Comment

by:propharma
ID: 35173034
So perhaps a stored proceedure that can be executed from any DB then?
0
 

Author Closing Comment

by:propharma
ID: 35487842
Very good explanation of the problem as well as an alternate solution to the core issue.  Thanks.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question