title: Updating Identity Column of a table with consecutive numbers through SQL Stored Procedure
body: <p>After deleting the duplicate records from the table,
  I want to update Identity column of a table with consecutive numbering starting with 1. Here is my table details </p>
  
  <pre><code>id(identity(1,1)),
  EmployeeID(int),
  Punch_Time(datetime),
  Deviceid(int)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/U5Lui.jpg" alt="enter image description here"></p>
  
  <p>I need to perform this action through a stored procedure.
  When i tried following statement in stored procedure</p>
  
  <pre><code>DECLARE @myVar int
          SET @myVar = 0
          set identity_insert TempTrans_Raw# ON
          UPDATE  TempTrans_Raw# SET  @myvar = Id = @myVar + 1
          set identity_insert TempTrans_Raw# off
  </code></pre>
  
  <p>gave error like...Cannot update identity column 'Id'
  Anyone please suggest how to update Identity column of that table with consecutive numbering starting with 1.</p>