How change the identity increment of column ?
Posted on 2010-04-14 16:35 nzperfect 阅读(351) 评论(0) 编辑 收藏 举报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
作者:nzperfect
出处:http://www.cnblogs.com/nzperfect/
引用或者转载本BLOG的文章请注明原作者和出处,并保留原文章中的版权信息。