Hey, I'm looking for the most efficient way to maintain an object relative auto-incrementing value. In other words, I have a table of objects, and a table of child objects. The child objects need to have a column, which increments relative to the other child objects for the same parent. (ie. child object 3 of parent object 4)
eg.
Parent Objects:
ID|name
1|Object1
2|Object2
3|Object3
Child Objects:
ID|relativeID|parentObjectID|name
1|1|1|Some Child Object
2|1|2|Some Child Object
3|2|1|Some Child Object
4|2|2|Some Child Object
4|3|1|Some Child Object
What's the most efficient way to generate the relativeID column? I'm thinking I should I query for the MAX(relativeID) with the same parentObjectID, then do a the insert, but I'm wondering if that would cause issues if there were concurrent inserts on the same parent object. Is there a better way to approach this?