Solved

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

Posted on 2008-06-18
3
155 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
In this article I will describe the Copy Database Wizard 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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

12 Experts available now in Live!

Get 1:1 Help Now