Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7005901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:24:34+00:00 2026-05-27T21:24:34+00:00

I created a stored procedure that has 9 inserts in summarized tables and the

  • 0

I created a stored procedure that has 9 inserts in summarized tables and the last statement is a delete.

This procedure takes around 9 minutes to execute for each given date, and one thing that I noticed is that if an error occurs and the first 3 inserts executed, it keeps the inserted data. To handle this, I created a begin try and begin transaction and a test that I did was to start the procedure using SSMS and after it started, I cancelled the command but the transaction was kept. How can I avoid this?

the procedure body is very simple… something like:

insert into...
insert into...
insert into...
insert into...
insert into...
insert into...
insert into...
insert into...
insert into...
insert into...
delete from....

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:24:35+00:00Added an answer on May 27, 2026 at 9:24 pm

    Two things:

    1) The basic syntax is:

    BEGIN TRY
    
      BEGIN TRAN
    
      INSERT...
    
      DELETE...
    
      COMMIT TRAN
    
    END TRY
    BEGIN CATCH
    
      IF (@@TRANCOUNT > 0)
      BEGIN
        ROLLBACK TRAN
      END
    
      DECLARE @ErrorMessage NVARCHAR(4000)
      SET @ErrorMessage = 'Line ' + CONVERT(VARCHAR(20), ERROR_LINE()) + ': '
                        + ERROR_MESSAGE()
      RAISERROR(@SQLErrString, 16, 1)
    
    END CATCH
    

    2) If you cancel a batch in process, you might need to run the ROLLBACK TRAN manually. You can test if you need to do this by doing a SELECT @@TRANCOUNT and if it is > 0 then call ROLLBACK TRAN.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created a package that contains a stored procedure that I plan to invoke
I've got a mySql stored procedure that looks like this-- delimiter | create procedure
I have a stored procedure that inserts batches of millions of rows, emerging from
I've created a stored procedure similar to the one below (I'm using this cut
I need to construct a single transaction / stored procedure that takes in two
A friend has created a few tables for me and used nvarchar(max) on around
I have a stored procedure that has been working just fine, but I recently
I need to create a stored procedure that upon exceution checks if any new
Let's assume, we create a stored procedure that is supposed to retrieve customer details
Suppose I have a stored procedure that manages its own transaction CREATE PROCEDURE theProc

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.