Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-06-03 : 08:41:02
|
| Wei writes "Hi:I want to use Identity column as my PK. But my problem is that when two processes are writting to the table at same time, how can I make sure that @@Idenity I get back is the correct one. In other words, when an new record is being added to the table and I have an new Identity value generated by SQL, I have to retrieve this @@Idenity and insert it into Child table, But my concern is that when I retrive this @@Identity, there may be another record being added to the table, so by the time I get this @@identity, it is not the one SQL frist inserts into the table anymore, so in this case, I lost one number or I may just put wrong number into child table FK column. Could you please tell me how to prevent this from happening? Or how to use this @@Idenity function so that the case like I mentioned above will not hapen? I know I can declare a local varible to hold this @@Idenity value,but not sure if it will help? Thank you very much for your help." |
|
|
graz
Chief SQLTeam Crack Dealer
4149 Posts |
Posted - 2002-06-03 : 08:41:03
|
| You should read the article we've already written on identity columns (http://www.sqlteam.com/item.asp?ItemID=8003). That should answer your question. |
 |
|
|
|
|
|