博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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,1primary key,name varchar(20))
go
insert into tb select 'a'
go 5

select * from tb

create table tb_tmp(id int identity(1000,5primary 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