Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start Transaction OR Begin Work

Tags:

mysql

percona

I don't know what is better to use Start Transaction OR Begin Work, and what is the difference.

like image 248
Motasem Avatar asked May 04 '12 22:05

Motasem


People also ask

How do you start a transaction?

To start a transaction, you use the START TRANSACTION statement. The BEGIN or BEGIN WORK are the aliases of the START TRANSACTION . To commit the current transaction and make its changes permanent, you use the COMMIT statement. To roll back the current transaction and cancel its changes, you use the ROLLBACK statement.

How do I start a transaction in SQL?

START TRANSACTION; SELECT @A:=SUM(salary) FROM table1 WHERE type=1; UPDATE table2 SET summary=@A WHERE type=1; COMMIT; With START TRANSACTION , autocommit remains disabled until you end the transaction with COMMIT or ROLLBACK . The autocommit mode then reverts to its previous state.

Why do we use begin transaction?

BEGIN TRANSACTION represents a point at which the data referenced by a connection is logically and physically consistent. If errors are encountered, all data modifications made after the BEGIN TRANSACTION can be rolled back to return the data to this known state of consistency.

How do MySQL transactions work?

In MySQL, the transactions begin with the statement BEGIN WORK and end with either a COMMIT or a ROLLBACK statement. The SQL commands between the beginning and ending statements form the bulk of the transaction.

How do I start and end a transaction in Oracle?

How to Begin and End Transactions. You begin a transaction with the first executable SQL statement (other than CONNECT) in your program. When one transaction ends, the next executable SQL statement automatically begins another transaction. Thus, every executable statement is part of a transaction.


1 Answers

From the MySQL manual:

BEGIN and BEGIN WORK are supported as aliases of START TRANSACTION for initiating a transaction. START TRANSACTION is standard SQL syntax and is the recommended way to start an ad-hoc transaction.

like image 70
eggyal Avatar answered Sep 24 '22 13:09

eggyal