Is auto-primary-key generation feature of Databases reliable?
database, sql
Solution
Yes, the auto increment primary key is reliable in that a duplicate key will never be generated. You have to be careful how you use it though.
- You should not assume that it will always increase in increments of exactly 1 (or whatever you set it to).
- You should not insert an entry and then without using transactions expect to be able to select max(id) to get the id of the record last inserted.
Problem
I have developed a web application and various clients can store records to that database simultaneously. I have set the auto-primary-key generation functionality of that database that generates a primarykey automatically (auto-increement) whenever a new record is added to the database. So my question is Can I rely on this auto-key-generation feature? Would there be no problem if various users are storing records simultaneously?