A
A
Artur Smirnov2012-12-12 07:52:33
MySQL
Artur Smirnov, 2012-12-12 07:52:33

mysql autoincrement

Good afternoon.
The question is how autoincrement works in mysql.
If I create two databases on different machines with a label A and fields id, name for example, and I will pass the id field as an auto-increment.
Then with an asynchronous but identical total amount of inserted data, will I get the same tables by id, name tuples?

I ask the question because I work with Oracle DB and there, if you do not set explicit order in the sequence, then in this case it will be possible to get tables in one database [(1,'name1'),(2,'name2')] and in another [(1,'name1'),(21,'name2')],

Answer the question

In order to leave comments, you need to log in

6 answer(s)
W
Wott, 2012-12-12
@wisd

>Oracle DB and there if in sequence to not set explicit observance of priority
In sense ORDER for SEQUENCE?
No, there is no such trick here and the field is always added sequentially.
If we take two different servers, with the same schemes and insert rows in the same sequence, then the resulting auto_increment fields will be identical. I did this at least several times (for example, I restored the state from the logs or transferred data from the working server to the development server or vice versa) and received identical tables.

L
la0, 2012-12-12
@la0

Yes, get identical (if all elements of the set id name are identical and the order is identical).
But if you need to avoid this on the contrary, then dev.mysql.com/doc/refman/5.1/en/replication-options-master.html#sysvar_auto_increment_increment
on A: auto_increment_increment=2 auto_increment_offset=1;
on B: auto_increment_increment=2 auto_increment_offset=2;
and you will have even on one and odd AI fields on the other

S
Sergey, 2012-12-12
@Ualde

There will be identical tables.

D
dali, 2012-12-12
@dali

Do not forget about transactions, if you use a transaction when writing to a table, then the auto-increment value of id is already reserved for the transaction, then roll back comes, there will be a gap between id.

D
doranych, 2012-12-12
@doranych

You will have different id when adding to tables asynchronously, unless of course you forcibly specify the id of the inserted record in the second table

O
oENDark, 2012-12-12
@oENDark

Add to one table then take lastinsertid and add to the second one without auto_incremenet

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question