开发者

Make my own incrementing mysql id without auto increment

开发者 https://www.devze.com 2023-03-07 11:59 出处:网络
How can I duplicate the function of an auto incrementing Id field without ma开发者_开发问答king the field itself auto incrementing? I suppose on my INSERT statement, I would need to somehow grab the l

How can I duplicate the function of an auto incrementing Id field without ma开发者_开发问答king 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)

0

精彩评论

暂无评论...
验证码 换一张
取 消