Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between END transaction and COMMIT transaction

I am trying to simulate a database recovery subsystem using java. However, I have the following questions.

Whenever begin transaction is issued, is it always necessary that there should be an end transaction? (Like the below example)

b1    --- Begin txn 1
r1(X) --- Read item X using txn 1
e1    --- End txn 1

As per the above example, I am not issuing a Commit transaction statement. So, will my transaction succeed or fail? If the above example, is as below,

b1    --- Begin txn 1
r1(X) --- Read item X using txn 1
c1    --- commit txn 1

what is the difference between end and commit?

Please let me know if you need more information.

like image 562
Ramesh Avatar asked Feb 11 '13 05:02

Ramesh


2 Answers

Either you ROLLBACK a Transaction Or COMMIT a Transaction.I hope you are not confusing it with BEGIN and END block which is not a transaction and nothing to do with Transaction at All.

I believe in most databases .... still it ends with a ROLL BACK or COMMIT.

Hope this helps.

like image 69
Tabish Sarwar Avatar answered Oct 14 '22 04:10

Tabish Sarwar


BEGIN/END delimits a block of code, without controlling a transaction. If not already inside a transaction, each statement will execute in an autonomous transaction. Typically BEGIN/END is used with branching/looping instructions (IF/WHILE).

BEGIN TRANSACTION / COMMIT TRANSACTION denotes the beginning of a transaction: each statement inside this block is executed in the same transaction and cannot be committed or rolled back individually.

like image 31
user2001117 Avatar answered Oct 14 '22 04:10

user2001117