Hi,
Can someone give me the syntax for the best way to go about inserting a row into a table with an auto-incrementing identity column as a primary key and then obtaining the new value after the insert? I am concerned about multiple users inserting at the same time and retrieving the wrong value. For instance, I could perform the insert and then select the max value, but if two people insert at the same time and my select is performed after the second insert, I lose the first insert value.
I imagine I need to do something with table locking, but I am not sure how to go about it.
Thanks in advance for your help.
Can someone give me the syntax for the best way to go about inserting a row into a table with an auto-incrementing identity column as a primary key and then obtaining the new value after the insert? I am concerned about multiple users inserting at the same time and retrieving the wrong value. For instance, I could perform the insert and then select the max value, but if two people insert at the same time and my select is performed after the second insert, I lose the first insert value.
I imagine I need to do something with table locking, but I am not sure how to go about it.
Thanks in advance for your help.