简体   繁体   中英

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.

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.

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.

For SQL transactions coming from inside a program like that, an END statement simply closes the transaction. Meaning that the transaction is finished and nothing more should be taking place. 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 needed as every query/statement should be committed.

More information about COMMIT can be found here .

If you are using ODBC for your database connection, information on transaction management can be found here .

Also this question has been asked before.

'End' is used to end the procedure/function. It is important for the statement to be executed.
'Commit' is being used to permanently save all changes in the transaction.
For example, you have created or deleted a table using SQL Statement, you will need to commit the changes.

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

The exact command names to begin and end a transaction depend on the specific database you use (unfortunately).

For example:

In SQLite , you use BEGIN / BEGIN TRANSACTION to begin, and END / END TRANSACTION / COMMIT / COMMIT TRANSACTION to end a transaction.

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

Please refer to this LINK for details

QUOTE: BEGIN TRANS and END TRANS begin and end a transaction. They DO NOT specify a new block of code; they only mark the transaction boundaries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM