How to add identity column with sequential values? Adding identity column in sql server's existing table does not create sequential number.
Asked
Active
Viewed 44 times
-2
-
1A normal identity column does use sequential values - what makes you think otherwise? – Dale K May 07 '19 at 03:37
-
4what do you mean by "not create sequential number"? – RoMEoMusTDiE May 07 '19 at 03:40
-
1it possible duplicate with https://stackoverflow.com/questions/282451/sql-identity-autonumber-is-incremented-even-with-a-transaction-rollback – masoud May 07 '19 at 04:28
-
Do you mean you want an existing table to have an identity column and you want to have the existing rows to automatically get sequential values? – Sami Kuhmonen May 07 '19 at 04:30
-
duplicate of: https://stackoverflow.com/questions/1049210/adding-an-identity-to-an-existing-column – Piotr Palka May 07 '19 at 04:35
1 Answers
1
declare @IdentityVal int
select @IdentityVal = MAX(id) from tbl_name
insert into tbl_name(id) select @IdentityVal

Hafsal Rh
- 191
- 1
- 3