Reputation: 4954
I am creating user detail table in MySQL where user details are stored when user submits registration form.
In my user table user id field is primary key and auto increment.
My application should be used by many users from many locations. Now there is one scenario when it is possible that two user clicks on submit button at same time from anywhere. My primary key is of integer type and has length of 15, but when two user clicks at same time then which user should get first next id. Or it is possible that none of that get registered and get error.
so what can i do in this case
Upvotes: 0
Views: 128
Reputation:
Your mySQL id
field is good, so you should have no problem; however, when inserting a new record, then depending on what your insert SQL query looks like, make sure you leave the id
undefined, or use something like:
insert into users values(NULL, "blah", "blah")
-where "NULL" is your first column / field.
This will only work the way you expect if the field (column) in place "NULL" is set (when created, or altered) to AUTO INCREMENT
.
If these are set, the record id is incremented on each data entry, no matter if it happens at the same time; new records are always queued to be inserted one after the other.
Upvotes: 2