I saw a lot of explanations why mysql skips some auto increment values ββ(and that this is not an error, since mysql never states that they should be sequential). I'm not sure why any of them apply to this simple test case. I don't know if the results will be the same in all recent mysql versions or not. Also add:
ALTER TABLE test_table2 AUTO_INCREMENT = 1;
between lines 2 INSERT INTO test_table2 does the order as expected.
Does anyone know why this simple case skipped identifiers 6 and 7?
CREATE TABLE test_table1 ( `id` INT NOT NULL AUTO_INCREMENT, `test` TEXT NOT NULL, PRIMARY KEY (`id`) ); INSERT INTO test_table1(`test`) VALUES('value 1'); INSERT INTO test_table1(`test`) VALUES('value 2'); INSERT INTO test_table1(`test`) VALUES('value 3'); INSERT INTO test_table1(`test`) VALUES('value 4'); INSERT INTO test_table1(`test`) VALUES('value 5'); CREATE TABLE test_table2 ( `id` INT NOT NULL AUTO_INCREMENT, `test` TEXT NOT NULL, PRIMARY KEY (`id`) ); INSERT INTO test_table2(`test`) SELECT `test` FROM test_table1; INSERT INTO test_table2(`test`) SELECT `test` FROM test_table1; SELECT * FROM test_table2;
Results of my mysql version:
'1', 'value 1' '2', 'value 2' '3', 'value 3' '4', 'value 4' '5', 'value 5' '8', 'value 1' '9', 'value 2' '10', 'value 3' '11', 'value 4' '12', 'value 5'
Thanks in advance.
source share