• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 63
  • Last Modified:

begin trans and roll back - doubts

Hello

I have a doubt about begin and commit and rollback.

I have a proc x and in this proc I started a begin trans, inside of my proc x, it calls a proc xy.

In the proc x I have two deletes for two tables (product, sallers) and inside of my proc xy I have one delete for my clie table.


if I call the rollback, the rollback will affect all the tables from proc x and proc xy?

thanks
Alex
0
hidrau
Asked:
hidrau
2 Solutions
 
ste5anSenior DeveloperCommented:
Sure, but do what all good developers do: implement it on a test system and test it. Gather knowledge.. get your own findings.
1
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
It really depends where and when you execute the rollback.
SQL Server engine will rollback everything executed from the last BEGIN TRAN until the last ROLLBACK and that's why you can use transaction blocks in case you what to commit or rollback blocks of transactions.
1
 
DBAduck - Ben MillerPrincipal ConsultantCommented:
The answer is as has been said by Vitor above. A BEGIN TRAN starts a transaction and EVERYTHING after that is in a transaction. The ROLLBACK statement will rollback EVERYTHING in the transaction from the first BEGIN TRAN.

COMMIT acts differently, You can BEGIN TRAN and then another BEGIN TRAN and these statements increases the count in @@TRANCOUNT by 1 each time BEGIN TRAN executes. The COMMIT statement decrements the number in @@TRANCOUNT and when the @@TRANCOUNT reaches 0 then the COMMIT finally commits all the statements.

Hope that helps.
0
 
hidrauAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now