日期:2014-05-18 浏览次数:20881 次
exec sp_configure 'allow updates',1
reconfigure with override
GO
update syscolumns set colstat = 0 where id = object_id('dbo.Sys_City') and colstat = 1
GO
update dbo.Sys_City
set ID=(select count(1) from dbo.Sys_City where ID<=t.ID)
from dbo.Sys_City t
GO
declare @a int
set @a=(select count(*) from dbo.Sys_City)
DBCC CHECKIDENT (Sys_City, RESEED, @a)
GO
update syscolumns set colstat = 1 where id = object_id('dbo.Sys_City') and name = 'ID'
GO
exec sp_configure 'allow updates',0
reconfigure with override
--不过多少列你要自已写,此处的col1,col2...是你的列
if object_id('sys_city_copy') is not null drop table sys_city_copy
select col1,col2... into sys_city_copy from sys_city--如果需排序,此处加入;
drop table sys_city;
select id=identity(int,1,1),col1,col2... into sys_city from sys_city_copy;
go
--如果你不在意你自增列的位置,可以这样,不过此自增列就跑到最后去了,呵呵
alter table sys_city drop column id;
alter table sys_city add id int identity(1,1) not null;
go
------解决方案--------------------
先改为非递增,改字段内容,最后改回自动递增
------解决方案--------------------
--先取消ID增,表->设计->ID列IDENTITY属性选为NO,然后
declare @id int=0
update tb set id=@id,@id=@id+1
--最后 将ID再重新改为自增表->设计->ID列IDENTITY属性选为YES 即可