I have 2 tables- master and detail table. Master Table has ID column which is Primary key and Auto Id. I have wrtten an SP to insert records into both tables. In this SP, when a record id inserted in master table, current_ident is fetched and stored in a variable which is then passed to detail table insert the detail records. This is working absolutely fine when transactions are done one by one. But when multiple users concurrently create the transactions sometimes the detail records of one transaction are getting inserted for some other transaction which is a dangerous thing. Please help me to resolve this issue.
Share
I would use the
SCOPE_IDENTITY()in this case.http://msdn.microsoft.com/en-us/library/ms190315.aspx