有数据的话
ALTER TABLE 表 ADD temp_id bigint identity(1,1) not null
go
SET IDENTITY_INSERT 表 ON
go
update tablename set temp_id=id
go
SET IDENTITY_INSERT 表 OFF
go
ALTER TABLE 表 DROP COLUMN 编号
go
exec sp_rename '表.temp_id','id'
go
ALTER TABLE 表 ADD temp_id bigint identity(1,1) not null
go
SET IDENTITY_INSERT 表 ON
go
update tablename set temp_id=id
go
SET IDENTITY_INSERT 表 OFF
go
ALTER TABLE 表 DROP COLUMN 编号
go
exec sp_rename '表.temp_id','id'
go
ALTER TABLE 表 ADD temp_id bigint identity(1,1) not null
go
SET IDENTITY_INSERT 表 ON
go
update tablename set temp_id=id
go
SET IDENTITY_INSERT 表 OFF
go
ALTER TABLE 表 DROP COLUMN id
go
exec sp_rename '表.temp_id','id'
go
感谢,思路很好的,但是这里不行啊?
select bigint identity(1,1) not null as temp_id,a.* into #temp from 表
然后在#temp进行操作,
操作完后再delete源表,最后将#temp导入源表
create table temp_table
(
id int,
name varchar(20)
)insert into temp_table values(3,'1')
insert into temp_table values(4,'1')
insert into temp_table values(5,'1')select * into #temp from temp_table
go
alter table #temp add temp_id int
go
alter table temp_table add temp_id int identity(1,1)update #temp set temp_id=id
set identity_insert temp_table on
delete from temp_table
insert into temp_table (temp_id,name) select temp_id,name from #temp
go
ALTER TABLE temp_table DROP COLUMN id
go
exec sp_rename 'temp_table.temp_id','id'
go
select * from temp_tabledrop table temp_table
drop table #temp
我试过了,可以搞定!