Solved

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

Posted on 2011-03-18
5
220 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 Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now