I was asked recently to confirm a consistent state of data in a
non-transactional MySQL table after a failing statement updating
multiple rows did not complete successfully.
Hmmm, this is what I did.
- Created a MEMORY table
- Populated with some data, and a Primary Key
- Updated the Primary Key so that it failed with a Duplicate
Key Error after updating only half the rows
- Confirmed that the rows that were updated, were, and the rows
that were not updated, were not
DROP TABLE IF EXISTS mem1;
CREATE TABLE mem1(
i1 INT UNSIGNED NOT NULL PRIMARY KEY,
c1 CHAR(10) NOT NULL,
dt TIMESTAMP)
ENGINE=MEMORY;
INSERT INTO mem1(i1,c1) VALUES (1,'a'), (2,'b'), (3,'c'), (4,'d'), (5,'e');
SELECT * FROM mem1;
+----+----+---------------------+
| i1 | c1 | dt |
+----+----+---------------------+
| 1 | a | 2007-06-14 17:26:29 |
| 2 | b | 2007-06-14 17:26:29 |
| 3 | c | 2007-06-14 …
[Read more]