title: Raiserror severity 16 does not rollbacks trigger
body: <p>I have a database running on SQL Server 2008.</p>
  <p>I have a trigger in which I raise error with severity 16. When I test the trigger the error appears but the operation is not rolled back, i.e. I have additional row in the table. I can not understand why is that, because severity 16 results in rollback. We also used that convention in other triggers and it terminates trigger and causes rollback.</p>
  <p>The table has also another trigger which does not allow deletion of rows.</p>
  <p>Here is the trigger:</p>
  <pre><code>    ALTER TRIGGER dbo.trg
      ON dbo.tbl
      AFTER INSERT, UPDATE
      AS
      BEGIN
        IF (@@ROWCOUNT &gt; 0)
        
          IF ((SELECT COUNT(SDS.ID) AS Count0 FROM dbo.tbl SDS WHERE SDS.IsIdleTimeReferred = 0) &lt;&gt; 1) OR 
             ((SELECT MAX(SDS.CreatedDate) FROM dbo.tbl SDS WHERE SDS.IsIdleTimeReferred = 0) &lt;
               (SELECT MAX(SDS.CreatedDate) FROM dbo.tbl SDS WHERE SDS.IsIdleTimeReferred = 1))
          BEGIN
            --IF @@TRANCOUNT &gt; 0 ROLLBACK
            RAISERROR('Only one record with value IsIdleTimeReferred=0 must exist and it must be the last one', 16, 1);
          END;
      END;
  </code></pre>
  <p>When I uncomment <code>@@TRANCOUNT</code> the operation behaves correctly.</p>
  <p>The table <code>tbl</code> consists of 3 columns:</p>
  <pre><code>[ID], [IsIdleTimeReferred], [CreatedDate]
  </code></pre>
  <p>I can not figure out where is the problem. For me code is designed correctly.</p>
  <p>Any ideas?</p>
  <p><strong>EDIT:</strong></p>
  <p>Ok, I agree that <code>Severity 16</code> does not rollback transaction in a trigger. So I implemented the following code (the trigger is <code>AFTER INSERT, UPDATE</code>):</p>
  <pre><code>BEGIN
    IF @@TRANCOUNT &gt; 0 ROLLBACK TRANSACTION;
    RAISERROR('Does not allow modifications in the past', 16, 1);
    RETURN;
  END;
  </code></pre>
  <p>This code does not rollbacks transaction in a trigger. If I switch rows and first <code>RAISERROR</code> and then <code>ROLLBACK</code> the changes are not rollbacked.</p>
  <p>Why this happening?</p>