自增长ID 越来越大,想重新从0开始排列 该怎么做?

来源:互联网 发布:管家婆软件操作流程 编辑:程序博客网 时间:2024/04/30 15:47
使用dbcc checkident检查和设置表的标识值
create table tb
(
 id int primary key identity,
 name varchar(50)
)
 insert into tb 
 select 'a'
 union all
 select 'b' 
 union all 
 select 'c'
 union all
 select 'd'
go
 dbcc checkident(tb,noreseed)
go
 
 
delete from tb where id>2
go
--删除记录后,表tb只剩下两条记录了,但是此时表tb的标识值仍为4,可以用下面的语句重置标识值为2
dbcc checkident(tb,reseed,2)
go
 
dbcc checkident(tb,noreseed)
go
 
/*检查标识信息: 当前标识值 '4',当前列值 '4'
DBCC 执行完毕。如果 DBCC 输出了错误信息,请与系统管理员联系。
 
(2 行受影响)
检查标识信息: 当前标识值 '4',当前列值 '2'
DBCC 执行完毕。如果 DBCC 输出了错误信息,请与系统管理员联系。
检查标识信息: 当前标识值 '2',当前列值 '2'
DBCC 执行完毕。如果 DBCC 输出了错误信息,请与系统管理员联系。*/
 
drop table tb
原创粉丝点击