Difference between END transaction and COMMIT transaction

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

When transactions start, is it always necessary for the transaction to be completed? (As shown below)

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

      

As per the example above, I am not doing a Commit transaction. So, will my transaction succeed or fail? If the above example is given 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.

+3


source to share


6 answers


Either you ROLLBACK a transaction or COMMIT a transaction. I hope you won't confuse it with the BEGIN and END block, which is not a transaction and is not related to a transaction at all.

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



Hope it helps.

+9


source


BEGIN/END

restricts a block of code without controlling the transaction. If not already in the transaction, each statement will be executed in an autonomous transaction. Usually BEGIN/END

used with branch / loop ( IF/WHILE

) instructions .



BEGIN TRANSACTION / COMMIT TRANSACTION

denotes the start of a transaction: each statement within this block is executed in the same transaction and cannot be transferred or canceled separately.

+1


source


'End' is used to end a procedure / function. This is important to follow the instructions.
"Commit" is used to permanently save all changes in a transaction.
For example, you created or deleted a table using a SQL Statement, you will need to commit the changes.

Read more about the Conclusion here.
http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_4010.htm

0


source


For SQL transactions coming from within such a program, the END statement simply closes the transaction. This means that the transaction is complete and nothing else should be. The COMMIT statement actually tells the database that you want the transaction changes to be PERMANENT.

If you are in "autocommit" mode, the COMMIT statement is not required as every request / statement must be committed.

More information on COMMIT can be found here .

If you are using ODBC to connect to a database, information on transaction management can be found here .

Also this question has been asked before.

0


source


The exact command names for starting and ending a transaction depend on the specific database you are using (unfortunately).

For example:

In SQLite, you use BEGIN / BEGIN TRANSACTION to start and END / END TRANSACTION / COMMIT / COMMIT TRANSACTION to end the transaction.

In MySQL, you use START TRANSACTION / BEGIN / BEGIN WORK and COMMIT / COMMIT WORK for this.

0


source


See LINK for details .

Quote: BEGIN TRANS and END TRANS start and end transaction. They DO NOT define a new block of code; they only mark transaction boundaries.

-1


source







All Articles