If i would be you, i would probably do something like this…
I would add a additional data-field into my db, which would detect all already used codes, when doing a DB-Query. → I hope i did not misunderstand your wished functionality.
Of course everything can be generated by code, that means…
-everytime when you a new registration, you also write corresponding values into your DB (update, save or insert).
