Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SQL Transactions for a single sql query [closed]

I have read a lot about SQL-transaction the pased few days. But i have not found an answer to my question. So maybe someone here can solve my problem?

The exact question is: Should i use a sql transaction for a single select/update/insert statement?

Or is it to overact to use SQL transactions for a single sql statement?

Thanks...

regards Ali

like image 562
Ali Avatar asked Nov 23 '25 06:11

Ali


1 Answers

Individual statements implicitly have their own transactions. By default, individual statements create and rollback/commit themselves. In theory, you can make it so that it will behave like an explicit transaction, although I can't think of a super great reason to do this. https://learn.microsoft.com/en-us/sql/t-sql/statements/set-implicit-transactions-transact-sql?view=sql-server-2017

The only reason I can think of to wrap an individual statement in its own explicit transaction is if you wanted to leave the transaction open so you could test something like blocking, or just maybe check the data while debugging before rolling it back.

like image 123
Xedni Avatar answered Nov 25 '25 20:11

Xedni



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!