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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:34:13+00:00 2026-05-10T15:34:13+00:00

Suppose I have a stored procedure that manages its own transaction CREATE PROCEDURE theProc

  • 0

Suppose I have a stored procedure that manages its own transaction

CREATE PROCEDURE theProc AS BEGIN    BEGIN TRANSACTION  -- do some stuff    IF @ThereIsAProblem     ROLLBACK TRANSACTION   ELSE     COMMIT TRANSACTION END 

If I call this proc from an existing transaction, the proc can ROLLBACK the external transaction.

BEGIN TRANSACTION EXEC theProc COMMIT TRANSACTION 

How do I properly scope the transaction within the stored procedure, so that the stored procedure does not rollback external transactions?

  • 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. 2026-05-10T15:34:13+00:00Added an answer on May 10, 2026 at 3:34 pm

    The syntax to do this probably varies by database. But in Transact-SQL what you do is check @@TRANCOUNT to see if you are in a transaction. If you are then you want to create a savepoint, and at the end you can just pass through the end of the function (believing a commit or rollback will happen later) or else rollback to your savepoint.

    See Microsoft’s documentation on savepoints for more.

    Support for savepoints is fairly widespread, but I think the mechanism (assuming there is one) for finding out that you’re currently in a transaction will vary quite a bit.

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

Sidebar

Related Questions

Suppose you have the following... An ASP.NET web application that calls a stored procedure
I have a big stored procedure that I run. At the end its supposed
I have a stored procedure that for now is just suppose to validate your
Suppose I have a PL/SQL stored procedure as follows: PROCEDURE do_something(foo VARCHAR2 DEFAULT NULL)
I have a stored procedure that goes something like this (pseudo code) storedprocedure param1,
I need a some stored procedure that called like: search('foo bar') makes a search
I have a stored procedure that uses a view to pull 6 averages. The
I have a simple question. Suppose I have a Stored Proceudre that returns a
I have a mysql 5.1, stored procedure that takes TEXT input which is supposed
I have a stored procedure that takes a uniqueidentifier as parameter. It is supposed

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.