Welcome Guest, Not a member yet? Register   Sign In
Transactions With Select and Single Inserts
#1

[eluser]asciiCode[/eluser]
I think I know the answer but I would like some confirmation.

1) I don't need to do a transaction when doing an select/get because nothing is being changed so nothing may need to be rolled back?

2) I don't need to do a transaction when only doing one insert? I can just test to see if the insert was successful?

Thanks!
#2

[eluser]slowgary[/eluser]
1) Yes!

2) Yes!

The purpose of transactions is to allow you to group a set of queries, where your RDBMS will treat the group of queries as "all or none".

The usual example is that of a bank transfer. If there are two queries involved with making a bank transfer - one that subtracts money from your account and one that adds it to mine, you'd only want the second query to be run if the first one was successful, otherwise there's a potential that money would be withdrawn from your account, but would not be deposited into my account. Thus, the money would just disappear.

Transactions allow your to solve this dilemma at the database level, instead of adding lots of application logic (this is especially helpful in cases where there are a lot more than 2 queries).




Theme © iAndrew 2016 - Forum software by © MyBB