Posted By

ezerick on 12/20/11


Tagged

sql


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

jnh
johnw


Auto Incremementing Id for Insert in T-SQL table


 / Published in: SQL
 

URL: http://snipplr.com/login/

This code allows you to create an ID field value for inserts into a table that does not auto increment itself

  1. declare @StartNumber int = 1000
  2.  
  3. INSERT INTO Table2 SELECT (ROW_NUMBER() OVER(ORDER BY [FIELD] DESC)) + @StartNumber AS id, * FROM Table1

Report this snippet  

You need to login to post a comment.