title: Primary key value after insertion of row in SQL Server 2005
body: <p>In SQL Server 2005 I am inserting a row into a table using  a stored procedure and I want to fetch the new primary key value just  after inserting that row. I am using following approach to get primary key value after insertion row</p>
  
  <pre><code>Create Proc Sp_Test
  @testEmail varchar(20)=null,-- Should be Unique
  @testName varchar(20)=null -- Should be Unique
  as
  
  begin
  
  insert into tableTest  (testUserEmail,testUserName)values (@testValue,@testName)
  
  select MAX(ID) from tableTest --ID is Primary Key 
  </code></pre>
  
  <p>--or</p>
  
  <pre><code>select ID from tableTest  where  testUserEmail =@testValue and testUserName = @testName
  </code></pre>
  
  <p>--or</p>
  
  <pre><code>select  SCOPE_IDENTITY() as ID
  
  end
  </code></pre>
  
  <p>Please suggest me which approach is better to perform described task.</p>