In my web application I have a simple employee form. Each employee has a unique id associated with it.
When a new employee is added to the system, a unique id is assigned to him. This id can be assigned manually or can be generated by the system.
We have a table where we have a single column with a number stored in it. It gets incremented by 1.
So if we have the table has a value of 10. System will auto generate an id of E0011 for next employee.
And the value in the table is updated to 11.
We have a button near “id” textfield. If user clicks on this button a new system generated id is created and populated in the id field.
Now, the problem is user can click on this field multiple times and generate the next id so the previous id is lost or consumed.
How do I prevent user from createing multiple ids?
Simple, don’t allow manual generation of IDs. In the first place, you have an automatic ID generator – why use it manually?
Let the system generate the ID (similar to auto-increment in MySQL) when his record is entered into the system. That way, the system controls the IDs (1 person = 1 id) and therefore no problem.
If you really want to go through the difficult route and manually generate IDs, then have an ID checker. This queries the database for that manually entered ID before inserting a record using that ID. If the ID is already in the system, then the insert fails. If not used yet, then proceed inserting the record.