Let’s have an example:
id (auto_increment) user
1 John
2 Mary
10 Christopher
How do I force a query to add new users with not used ids? :In our case from 3 to 9:
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could do this with a bit of clever SQL by setting the ID of the record you wish to insert to the first “missing” ID value of the table:
You may not be able to do this in one query, depending on DBMS. This approach also pretty much renders making the Id column an “auto-generate” column useless; this insert would always find the minimum value that didn’t have an ID, whether that’s the one the identity generator would try to use or not, and you would pretty much always have to enable “identity insert” before inserting to the table, so the auto-gen feature on this table would never be used.