cancel
Showing results for 
Search instead for 
Did you mean: 

Add or update field with autoincrement starting at a specific number

0 Kudos
694

I am wanting to update the customernum field starting at 211001 and increment by 1. I can't find a script that makes it that simple. The scripts I found are based on another field and I have tried to adjust for that. It is not working. Do you know something I can use for something that simple?

Accepted Solutions (0)

Answers (2)

Answers (2)

VolkerBarth
Contributor

I assume that column has an AUTOINCREMENT default. You can then

  • either explicitly set the value for an autoincrement column (because it's just a default for that column, and defaults can of course be overriden, so you could just insert the first row with number 211001),

  • or you can use the builtin stored procedure sa_reset_identity() to provide the next value. (Note: The value there is the "last one used", so you would set it to 211000.)

Autoincrements are always incremented by 1. For other steps, you would need a sequence instead.

0 Kudos

This is what I found that worked

DECLARE @id INT SET @id = 211001 UPDATE OKF_CUST SET customernum = @id, @id = @id + 1;