Jump to content

Recommended Posts

My question is fairly simple. There seem to be two ways of incrementing the 'ID' field of a new record. One is to find the maximum ID, add one, and use that new value as the ID. Or one can use an auto-incrementing field. Why would someone use one method versus another? When is auto-incrementing not appropriate?
Link to comment
https://forums.phpfreaks.com/topic/14678-new-user-ids-use-max-or-auto-increment/
Share on other sites

UID fields should always be auto-increment.. MAX() is unreliable, because you don't have consistent reads in MySQL with MyISAM table without transactions, so you can't be sure that you're adding one to the "last" record.  Auto-incrementing is always appropriate for uids; sometime count=count+1 makes sense for other fields, but the same warning applies.
[quote author=fenway link=topic=100678.msg397727#msg397727 date=1152978386]
UID fields should always be auto-increment.. MAX() is unreliable, because you don't have consistent reads in MySQL with MyISAM table without transactions, so you can't be sure that you're adding one to the "last" record.  Auto-incrementing is always appropriate for uids; sometime count=count+1 makes sense for other fields, but the same warning applies.
[/quote]
Then should I use an InnoDB table (and then use transactions?) I mean... is there any advantage to that (why does't everybody use auto_increment?)
When I do that, the only thing unique about the record would be the auto-incremented ID; does that mean I don't have to wrap it in a transaction? (If two people create accounts at the same time... MySQL won't assign the same auto-id?)

(pardon my ignorance... if you have any decent tutorials on this kind of thing, please point me to the url)
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.