CREATE TABLE `test` ( `id` int(11) NOT NULL AUTO_INCREMENT, `number` int(10) UNSIGNED NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO test(number) SELECT COALESCE(MAX(number), 0) + 1 FROM test;
In other words, if I have this statement executed in parallel multiple times, should I be worried that the same
number could be inserted twice? I obviously will create a
UNIQUE key (which will in fact be a composite key, that's why the classic
AUTO INCREMENT feature does not fit my needs), but in that case should I be worry that a
UNIQUE CONSTRAINT error might be thrown?