简体   繁体   中英

Transactions in mysql with InnoDB engine getting saved even with incomplete transaction?

I was learning about transactions in RDBMS and i thought I would test it with this piece of code:

DELIMITER $$ START TRANSACTION; INSERT INTO test4 VALUES (0,2); INSERT INTO test4 VALUES (2,2); INSERT INTO test4 VALUES (3,2); INSERT INTO test4 VALUES (4,2); INSERT INTO est4 VALUES (4,2); INSERT INTO test4 VALUES (6,2); INSERT INTO test4 VALUES (7,2); INSERT INTO test4 VALUES (8,2); INSERT INTO test4 VALUES (9,2); INSERT INTO test4 VALUES (10,2); INSERT INTO test4 VALUES (11,2); INSERT INTO test4 VALUES (12,2); END; DELIMITER ;

I intentionally kept the 5th insert statement incorrect so that I could test how transaction works. When I executed the query, MySQL threw an error as expected but all the queries upto the 4th insert were still saved in the table! Why is it happening? And yes I am using InnoDB engine which supports transaction. I use 14.14 version of MySQL. Also, I was wondering what is the use of savepoints? Suppose I use savepoints in my transaction so that I could rollback to last successful transaction savepoint in case of a failed after transaction. What happens after the transaction is terminated due to failure? What roll does savepoint play from then on? Thanks!

你可以用魔杖检查自动提交: http//dev.mysql.com/doc/refman/5.0/en/commit.html

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