Solved

How do I continue with an update if the table's trigger is causing an error?

Posted on 2008-06-18
3
160 Views
Last Modified: 2010-03-19
If I update a record in my e.g. "Address" table, an update trigger attempts to insert the record from the "Deleted" table into a separate archive table.

If for some reason that trigger encounters an error, my stored procedure for updating an address fails completely even though there's nothing wrong with the original update.

The archiving of old "Address" records is not high priority so I would like to know how allow the original (error-free) update to go ahead regardless of whether the trigger has a problem. I had considered using the update stored procedure to perform the update and the archive but then I don't have access to the "Inserted/Deleted" tables.
0
Comment
Question by:milesryoung
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
chapmandew earned 125 total points
ID: 21812219
It is because the trigger executes in the same transaction scope as the original update.

If you're using 2005, you still have access to the inserted/deleted tables on the update outside of the trigger if you use the OUTPUT clause:

http://articles.techrepublic.com.com/5100-10878_11-6074046.html
0
 

Author Comment

by:milesryoung
ID: 21812682
Thanks for your reply. That is interesting to know but the OUTPUT part would be nested inside the main update/insert. If that caused an error (like how the trigger would) I couldn't continue with the normal update/insert could I? You do deserve a point or 50 for bringing "OUTPUT" to my attention though :-)
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 21812710
Yes, it can.  If you insert the changes into a table properly then you should be fine...it is just capturing what is modified. From there, its just like a procedure and you can use that altered data as you see fit.  So, so long as you have the insert statement into the table setup properly from the OUTPUT statement then you should be good.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

617 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