title: @@IDENTITY, SCOPE_IDENTITY(), OUTPUT and other methods of retrieving last identity
body: <p>I have seen various methods used when retrieving the value of a primary key identity field after insert.</p>
  
  <pre><code>declare @t table (
      id int identity primary key,
      somecol datetime default getdate()
  )
  insert into @t
  default values
  
  select SCOPE_IDENTITY() --returns 1
  select @@IDENTITY --returns 1
  </code></pre>
  
  <p>Returning a table of identities following insert:</p>
  
  <pre><code>Create Table #Testing (  
      id int identity,  
      somedate datetime default getdate()  
  )  
  insert into #Testing  
  output inserted.*  
  default values   
  </code></pre>
  
  <p>What method is proper or better? Is the OUTPUT method scope-safe?</p>
  
  <p>The second code snippet was borrowed from <a href="http://sqlinthewild.co.za/index.php/2008/12/31/on-the-output-of-a-data-modification/#more-124" rel="noreferrer">SQL in the Wild</a></p>