Tuesday, September 11, 2012

Performing transactions with BEGIN and COMMIT


These statements provide control over use of transactions:
ž  START TRANSACTION or BEGIN
›      start a new transaction.
COMMIT
›      commits the current transaction, making its changes permanent
ž  ROLLBACK
›      rolls back the current transaction, canceling its changes
ž  SET autocommit
›      disables or enables the default autocommit mode for the current session

CREATE TABLE t (f INT) TYPE=InnoDB;
BEGIN;
INSERT INTO t(f) VALUES (1);
SELECT * FROM t;
ROLLBACK;
SELECT * FROM t;

CREATE TABLE t (f INT) TYPE=InnoDB;
BEGIN;
INSERT INTO t(f) VALUES (1);
SELECT * FROM t;
COMMIT;
ROLLBACK;
SELECT * FROM t;



No comments:

Post a Comment