Make my own incrementing mysql id without auto increment

问题描述:

How can I duplicate the function of an auto incrementing Id field without making the field itself auto incrementing? I suppose on my INSERT statement, I would need to somehow grab the last id created, and add +1 on the new entry. But I don't know how. Any help is appreciated.

EDIT: I ended up taking ypercube's advice and keeping the id field as autoincrementing and making my searchstring unique. Thanks!

网友答案:

You'd need to select the highest current ID in one query, then use that when inserting using a second query.

To get round the race conditions, you could create a table lock (nasty) or use transactions (better, but not ideal)