7.31 BEGIN/COMMIT/ROLLBACK Syntax
By default, MySQL runs in autocommit mode. This means that as soon as you execute an update, MySQL will store the update on disk.
If you are using BDB tables, you can put MySQL into non-autocommit mode with the following command:
SET AUTOCOMMIT=0
After this you must use COMMIT to store your changes to disk or ROLLBACK if you want to ignore the changes you have made since the beginning of your transaction.
If you want to switch from AUTOCOMMIT mode for one series of statements, you can use the BEGIN or BEGIN WORK statement:
BEGIN;
SELECT @A:=SUM(salary) FROM table1 WHERE type=1;
UPDATE table2 SET summmary=@A WHERE type=1;
COMMIT;
Note that if you are using non-transaction-safe tables, the changes will be stored at once, independent of the status of the autocommit mode.
If you do a ROLLBACK when you have updated a non-transactional table you will get an error (ER_WARNING_NOT_COMPLETE_ROLLBACK) as a warning. All transactional safe tables will be restored but any non-transactional table will not change.
If you are using BEGIN or SET AUTO_COMMIT=0, you should use the MySQL binary log for backups instead of the old update log; The transaction is stored in the binary log in one chunk, during COMMIT, the to ensure and ROLLBACK:ed transactions are not stored. See section 22.4 The Binary Log.
The following commands automaticly ends an transaction (as if you had done a COMMIT before executing the command):
ALTER TABLE BEGIN CREATE INDEX
DROP DATABASE DROP TABLE RENAME TABLE
TRUNCATE
Beantworte nie Threads mit mehr als 15 followups...
Real programmers confuse Halloween and Christmas because OCT 31 = DEC 25
Original geschrieben von Radium2k wie kann ich rausfinden ob die rollback kann ? ist MySQL 4.x
Kommt letztlich drauf an welchen Table-Handler Du verwendest (InnoDB, BDB, Gemini) ... MyISAM kann's auf gar keinen Fall!
carpe noctem
[color=blue]Bitte keine Fragen per EMail ... im Forum haben alle was davon ... und ich beantworte EMail-Fragen von Foren-Mitgliedern in der Regel eh nicht![/color] [color=red]Hinweis: Ich bin weder Mitglied noch Angestellter von ebiz-consult! Alles was ich hier von mir gebe tue ich in eigener Verantwortung![/color]
Kommentar