title: How to use SCOPE_IDENTITY to retrieve the last ID that was inserted
body: <p>Suppose I have two table. First table's primary key is the foreign key for another table. </p>
  
  <p>Table <code>Member</code> has its primary key as the foreign key in <code>Member_detail</code>. </p>
  
  <p>So when I insert a row in <code>Member</code> table using a Stored Procedure, I need to get the primary key value to add to the <code>Member_detail</code> table. </p>
  
  <p>One way I was using is :</p>
  
  <pre><code>SELECT Max(MemberID) 
  FROM Member
  </code></pre>
  
  <p>Then passing this <code>Memberid</code> to my <code>Member_detail</code> table, but on the <a href="https://stackoverflow.com/questions/6799738/primary-key-value-after-insertion-of-row-in-sql-server-2005">following post</a>, I read that the <code>Max</code> function is not recommended and that I should use <code>SCOPE_IDENTITY</code>, but I don't know how to use of it. </p>
  
  <p>Can anyone give me some example?</p>