How I can change identity column?
Example I have table:
CREATE TABLE orders
(
id int IDENTITY(100,1)
Name varchar(250)
)
And I need to change as
CREATE TABLE orders
(
id int IDENTITY(1000,1)
Name varchar(250)
)
How I can change identity column?
Example I have table:
CREATE TABLE orders
(
id int IDENTITY(100,1)
Name varchar(250)
)
And I need to change as
CREATE TABLE orders
(
id int IDENTITY(1000,1)
Name varchar(250)
)
Basically you want to change the seed of your identity column. you can do using the dbcc command as follows
DBCC CHECKIDENT('orders' , RESEED , 1000)
You can do something like this if you want exiting columns to be updated aswell
NB: Your switch table must be exactly like your orders table. Same columns etc and in same order.
CREATE TABLE orders_switch
(
Name varchar(250) ,
id int IDENTITY(1000,1)
)
insert into orders_switch
select [Name] from orders
truncate table dbo.orders alter table [dbo].[orders_switch] switch to [dbo].[orders]
declare @max int
set @max = (select MAX(id) +1 from dbo.orders)
DBCC CHECKIDENT('orders' , RESEED , @max )