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 8799401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:18:50+00:00 2026-06-14T00:18:50+00:00

My SQL-Server learning curve has been back-to-front and after several yrs I’m battling to

  • 0

My SQL-Server learning curve has been back-to-front and after several yrs I’m battling to use TRANSACTION code effectively.

If COMMIT TRANSACTION is not explicitly stated then at the point of ROLLBACK TRANSACTION if no errors have occurred in preceding code will the transaction then be committed? The question is in connection with a structure like the following:

USE MyDataBase;
GO
     BEGIN TRANSACTION;
        --complex query X here  
     ROLLBACK TRANSACTION; PRINT N'Rolled back the transaction.';
GO

…I thought ROLLBACK TRANSACTION was used in a situation where you do not want changes to be made to a db if an error has occured in the preceding script – in the above this would be X. If i wanted to explicitly state COMMIT TRANSACTION in the above then where should it be located?

To confuse myself even more I’ve got the following – why is it rolling back twice? Is an error occuring to create the ROLLBACK?

USE WHAnalysis;
GO
    BEGIN TRANSACTION;

        IF @@TRANCOUNT = 1
            SELECT @@TRANCOUNT
            --do a complex query here

    ROLLBACK TRANSACTION; PRINT N'Rolled back the transaction.';
GO
  • 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-06-14T00:18:51+00:00Added an answer on June 14, 2026 at 12:18 am

    No. The transaction will remain open and uncommitted until it is committed, which will probably eventually cause blocking on your database.

    If transactions are nested, rollback will rollback to the beginning of the outer transaction, not the inner transaction – See http://msdn.microsoft.com/en-us/library/ms181299.aspx

    I would consider a structure something like

     begin try
          begin tran
          -- do query
          commit tran
     end try
     begin catch
          if @@trancount>0 
          begin
              rollback
          end
          -- handle error here
     end catch
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning how to use SQL Server Management Studio and can't figure out how
I have visual studio 2010 only with no sql server.I use it for learning.Now
I'm having a go at learning to use SQL Server CE databases as a
I'm playing around and learning to use Microsoft SQL Server. I want to store
I am learning how to use the Service Broker of SQL Server 2008 R2.
I'm learning SQL Server Compact for a program I'm writing that requries a local
My only experience with Machine Learning / Data Mining is via SQL Server Analysis
The setup: Winform/ASP.NET MVC projects. Learning NHibernate SQL-Server driven apps I work with clients
SQL Server provides the type [rowguid]. I like to use this as unique primary
I am learning and using SQL Server 2008 new Merge statement, merge statement will

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.