?
Solved

After Insert Trigger & Rollback

Posted on 2006-07-06
3
Medium Priority
?
1,526 Views
Last Modified: 2010-05-19
If a Stored Procedure contains an insert statement wrapped in a transaction and that transaction is rolled back in the procedure, does the after trigger still fire? Or is the trigger only called upon the commit statement?

Thanks.
0
Comment
Question by:AMLabels
[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 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17049377
if the procedure is like this:

  begin transaction
    insert into table ...
  rollback

and the table has a insert trigger, the trigger WILL fire
0
 

Author Comment

by:AMLabels
ID: 17049526
would the rowcount from the inserted table work to identify whether the stored procedure's insert had indeed been successful?
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1000 total points
ID: 17049611
to clarify:
  if the insert statement fails as such due to data type problems for example; the trigger will NOT raise.
  as soon as the insert could do it's initial job, the trigger will be raised even if the insert inserted 0 rows:
 insert into sometable select * from othertable where <condition>
  with a condition that will make that 0 rows are inserted
  -> the trigger WILL raise, but indeed with 0 rows in the "INSERTED" table (better use that than rowcount)

0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

801 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