title: Getting the primary key of an newly inserted row in SQL Server 2008
body: <p>I have a bunch of data which will insert into a table. This issue is that I need it to return the primary key to that table. I wasn't sure if there was things like:</p>
  
  <pre><code> insert into TABLE (...) values (...) RETURNING p_key
  </code></pre>
  
  <p>or</p>
  
  <pre><code> select p_key from (insert into TABLE (...) values (...))
  </code></pre>
  
  <p>I am making a workaround for a browser and saved information which will more or less add a row and then update it... but without the primary key, there is no way to update it as there is no reference to it.</p>
  
  <p>I was looking online and found some examples via google, but it confused me slightly with these examples.</p>
  
  <p><a href="http://en.wikipedia.org/wiki/Insert_(SQL)#Retrieving_the_key">http://en.wikipedia.org/wiki/Insert_(SQL)#Retrieving_the_key</a></p>
  
  <p><a href="http://www.daniweb.com/web-development/databases/ms-sql/threads/299356/returning-identity-of-last-inserted-row-uniqueidentifier">http://www.daniweb.com/web-development/databases/ms-sql/threads/299356/returning-identity-of-last-inserted-row-uniqueidentifier</a></p>
  
  <p>Wikipedia was saying that for SQL Server 2008 to use <code>OUTPUT</code> instead of <code>RETURNING</code>,  possible to use something like <code>OUTPUT p_key</code></p>