当前位置: 动力学知识库 > 问答 > 编程问答 >

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)

分享给朋友:
您可能感兴趣的文章:
随机阅读: