I’m creating a messaging system (using PHP) and want to assign an ID number to each message (aside from each actual message having an unique ID number)…however, if someone replies to a message then i want to be able to give that message the same ID as the message being replied to…then of course I can disply them by time and show them in order.
So, if i give the field an auto_increment type is that able to be overwritten?
Meaning…each new message has auto value e.g. 1, 2, 3 etc but someone replies to number 2 so it’s ID needs to also 2
Or is there a better way to do this?
Absolutely nothing prevents you from assigning any arbitrary value to an
AUTO_INCREMENTcolumn. If necessary, the table counter will adjust accordingly.However, you cannot set as
AUTO_INCREMENTa column that’s not unique.Honestly, I can’t understand your design. A typical messaging system would look like this:
Duplicating IDs kind of beats the purpose of using IDs.
Update #1: OMG, it seems that it can actually be done under certain circumstances:
http://dev.mysql.com/doc/refman/5.5/en/example-auto-increment.html
Update #2: For the records, I’ve just tested it and you can use duplicate auto-incremented IDs in InnoDB tables as well: