begin trans and roll back - doubts


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?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
hidrauAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.