I’m no expert at SQL, just know some nesseary basics, but I need to refactor my LINQ code into SPROCs for better perfomance andI have this scenario.
I have Two tables Threads and Posts.
While I’m creating Thread I also need to create post. It’s one-to-many relationship (one Thread may have many posts). But while creating thread I have no way of know what ID thread will have becaause it’s autogenerated Identity.
I thought I cloud simply first create thread and later Select last added thread, but How can I be sure it will be exactly the thread I want ?
Read the following article @@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT – Retrieve Last Inserted Identity of Record for a detailed explanation.