Log in
::
Register
::
Not logged in
Search:
Home
Articles
Editorials
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Advertise
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
General
»
How to add a trigger to copy table to archive...
How to add a trigger to copy table to archive table
Rate Topic
Display Mode
Topic Options
Author
Message
halv235
halv235
Posted Tuesday, November 03, 2009 2:45 PM
Grasshopper
Group: General Forum Members
Last Login: Thursday, November 12, 2009 10:32 AM
Points: 12,
Visits: 17
I have a database that I want to start archiving. It contains 2 tables that I am going to archive to a new archive_database. I want to add a trigger to the current tables to automatically upadate the archive table for updates and inserts. I will then purge off data that is over n days on the current database and the archive_database will always show complete history.
I don't have any experience with triggers and am looking for suggestions.
thanks.
Post #813253
GSquared
GSquared
Posted Tuesday, November 03, 2009 2:48 PM
SSCertifiable
Group: General Forum Members
Last Login: Yesterday @ 1:27 PM
Points: 7,838,
Visits: 4,282
Don't do it in a trigger. Set up a job that archives data on a scheduled basis. That almost always works better.
- GSquared
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #813257
Elliott W
Elliott W
Posted Tuesday, November 03, 2009 3:16 PM
SSCommitted
Group: General Forum Members
Last Login: Today @ 8:19 AM
Points: 1,834,
Visits: 1,287
I'm with GSquared on this, doing it in a trigger is likely to cause unforseen issues.
You are aware that triggers are synchronous, meaning that they have to complete before whatever caused them to run gets control back, in other words the update statement that fired the trigger will be sitting there waiting until the trigger gets all the way done with whatever it is doing.
Because you can't know how much will be archived in any single execution this creates a case where performance will be indeterminable and sometimes will be ok and others less so but you can't predict it ahead of time. From a users perspective this is not good.
Best answer, create a stored procedure that performs the archival and using SQL Agent schedule it at least once a day.
CEWII
--------------------------------
Having trouble figuring out what jobs are running in SQL Server at the same time.
Try
Sql Job History Visualization
It lets you view your SQL Job history on an Outlook style calendar..
Post #813285
DiverKas
DiverKas
Posted 2 days ago @ 9:11 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: 2 days ago @ 9:15 AM
Points: 111,
Visits: 115
G-Squared is right. I would NEVER recommend a trigger in this situation for a more insidious reason than mentioned above. Since triggers can be fired simultaneously from multiple SQL statements, you could, depending on the level of transaction handling you choose, either A) create masses of duplicate archive records for each trigger firing, B) deadlock the processes because each is trying to transact the archival of the records.
This is definitely a Job that should be scheduled off hours.
Post #821710
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2009 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use