Following statement can reset seed
DBCC CHECKIDENT (tb,RESEED,5)
but can't reset increment.
how change the identity increment of column?
I can't find the simple method,now I use Following sql script to change it.
use tempdb
go
if exists(select * from sys.tables where name='tb')
drop table tb
go
create table tb(id int identity(1,1) primary key,name varchar(20))
go
insert into tb select 'a'
go 5
select * from tb
create table tb_tmp(id int identity(1000,5) primary key,name varchar(20))
go
set identity_insert tb_tmp on
insert tb_tmp(id,name) select id,name from tb with(xlock,tablock)
set identity_insert tb_tmp off
drop table tb
go
exec sp_rename N'tb_tmp',N'tb'
go
insert into tb(name) select 'b'
go 5
select * from tb
go
if exists(select * from sys.tables where name='tb')
drop table tb
go
create table tb(id int identity(1,1) primary key,name varchar(20))
go
insert into tb select 'a'
go 5
select * from tb
create table tb_tmp(id int identity(1000,5) primary key,name varchar(20))
go
set identity_insert tb_tmp on
insert tb_tmp(id,name) select id,name from tb with(xlock,tablock)
set identity_insert tb_tmp off
drop table tb
go
exec sp_rename N'tb_tmp',N'tb'
go
insert into tb(name) select 'b'
go 5
select * from tb
please tell me if you find bugs
thanks for reading,
nzperfect