Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does it drop temp table (created in transaction) if rollback transaction in sql server?

In the transaction, I created some temp tables and inserted some data. if everything goes ok, the temp tables will be dropped and then the transaction will be committed. if there is exception, the connection will be close.

My question is: Do I have to rollback the transaction before close the connection? or, as long as the connection is closed, it is ok?

If I rollback, I assume the temp tables created in transaction will be dropped (rollback) too, correct?

thanks

like image 747
urlreader Avatar asked Nov 21 '25 19:11

urlreader


1 Answers

A temp table will be dropped when it's out of scope.

However losing a connection while having a transaction open creates an orphaned transaction, and any locks it holds will remain.

Using SET XACT_ABORT should rollback any transaction as soon as a run-time error is encountered.

http://msdn.microsoft.com/en-us/library/ms188792.aspx

like image 158
deeg Avatar answered Nov 24 '25 10:11

deeg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!