I have user defined objects which i store in a MySQL database. One approach i use for this is to have the user defined objects essentially be a “front” end to the MSQL database. So, for example a User.Insert(aName) would insert a new row in the user table. The user table has two columns a UserID which is an autoincrement index field, and UserName VarChar.
inside of the user object i also include a UserID property. I am now wondering what the best way is to ensure that the UserId property in the User object is the one assigned by autoincrement when a newly user is included.
Right now i am basically writing an insert and then immediately reading the record out again (by name), so that i retrieve the user id. But this is likely bad practice since names may not be unique.
Should i create app defined IDs and use them instead of auto generated indexes, or in addition to them? What is best practice?