我的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”。
请帮助我!
由于
答案 0 :(得分: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 |
+------------+---------+------------------------------------------------------------+--------------+------+------------+
答案 1 :(得分:-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)