0
做一個簡單的交易:MySQL的:交易不會回滾
START TRANSACTION;
INSERT INTO users_trips VALUES ('1', '1');
INSERT INTO users_trips VALUES ('1', '41'); <-- this fails due to foreign key contraints
COMMIT;
然而,第一條記錄仍然存在。我正在使用InnoDB引擎。
mysql> show create table users_trips;
+-------------+--------------------------------------------------------------------------------
| Table | Create Table
+-------------+--------------------------------------------------------------------------------
| users_trips | CREATE TABLE `users_trips` (
`user_id` int(11) NOT NULL DEFAULT '0',
`trip_id` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`user_id`,`trip_id`),
KEY `users_trips_trip_id_fk` (`trip_id`),
CONSTRAINT `users_trips_trip_id_fk` FOREIGN KEY (`trip_id`) REFERENCES `trips` (`trip_id`),
CONSTRAINT `users_trips_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------------+--------------------------------------------------------------------------------
1 row in set (0.00 sec)
爲什麼不回滾?
謝謝
您在遇到錯誤時沒有回滾。 – Tarik