有数据的话
ALTER TABLE 表 ADD 编号1 bigint identity(1,1) not null
go
SET IDENTITY_INSERT 表 ON
go
update tablename set 编号1=编号
go
SET IDENTITY_INSERT 表 OFF
go
ALTER TABLE 表 DROP COLUMN 编号
go
exec sp_rename '表.编号1','编号'
go
ALTER TABLE 表 ADD 编号1 bigint identity(1,1) not null
go
SET IDENTITY_INSERT 表 ON
go
update tablename set 编号1=编号
go
SET IDENTITY_INSERT 表 OFF
go
ALTER TABLE 表 DROP COLUMN 编号
go
exec sp_rename '表.编号1','编号'
go
还有一个方法就是
先导入临时表
select IDENTITY(int,1,1) as rid,* into #tmp from yourtable
然后drop yourtable
再重建表
不过这方法对与数据量大的话 就不太合适了
drop table yourtable
select #tmp into yourtable
drop table yourtable
select * into yourtable from #tmp:)