2

我的 SQL 代码是:

SET AUTOCOMMIT=0;
START TRANSACTION;
BEGIN;
INSERT INTO utente(nomeutente) VALUES('pippobaudo');
INSERT INTO fonti(id_fonte, id_esame) VALUES (4, 28);
COMMIT;

第一个INSERT 是正确的,但第二个是不正确的,因为我想测试交易。MySQL 理解并在第二次 INSERT 中生成错误,但令人难以置信的是不尊重事务并在我的数据库中插入“pippobaudo”。

请帮我!

谢谢

4

2 回答 2

4

MyISAM 引擎不支持事务:

mysql> show engines;
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine     | Support | Comment                                                    | Transactions | XA   | Savepoints |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                      | NO           | NO   | NO         |
| CSV        | YES     | CSV storage engine                                         | NO           | NO   | NO         |
| MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance     | NO           | NO   | NO         |
| InnoDB     | YES     | Supports transactions, row-level locking, and foreign keys | YES          | YES  | YES        |
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables  | NO           | NO   | NO         |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
于 2013-10-03T15:51:00.490 回答
-1

将 IGNORE 添加到 INSERT 中,这会强制生成警告而不是事务中的错误。

SET AUTOCOMMIT=0;
START TRANSACTION;
BEGIN;
INSERT IGNORE INTO utente(nomeutente) VALUES('pippobaudo');
INSERT IGNORE INTO fonti(id_fonte, id_esame) VALUES (4, 28);
COMMIT;

注意:MyISAM 可以在事务中完成,但它不是完整的实现,这意味着您无法撤消更改(ROLLBACK)

于 2013-10-03T15:53:48.973 回答