select * into # from tb order by id truncate table tb insert into tb select * from # drop table #
如果想另生成id 可用 select identity(int,1,1) as iden,* into # from tb truncate table tb insert into tb select iden,col2,col3.. from # drop table #
使用下面的语句将ID排序 declare @i int select @i = 0 update table表 set @i = @i+1,id = @i 然后将列设置为自增加的。
要么把id列设置为标识列,要么在id列上建立索引(升序)
hrb2008() 的方法不行 select identity(int,1,1) as iden,* into # from tb truncate table tb insert into tb select iden,col2,col3.. from # drop table # tb表中的,iden为标识符号,插入时会报错!应该是: set identity_insert tb on select identity(int,1,1) as iden,* into # from tb truncate table tb insert into tb select iden,col2,col3.. from # drop table # set identity_insert tb off
truncate table tb
insert into tb select * from #
drop table #
可用
select identity(int,1,1) as iden,* into # from tb
truncate table tb
insert into tb select iden,col2,col3.. from #
drop table #
declare @i int
select @i = 0
update table表 set @i = @i+1,id = @i
然后将列设置为自增加的。
select identity(int,1,1) as iden,* into # from tb
truncate table tb
insert into tb select iden,col2,col3.. from #
drop table #
tb表中的,iden为标识符号,插入时会报错!应该是:
set identity_insert tb on select identity(int,1,1) as iden,* into # from tb
truncate table tb
insert into tb select iden,col2,col3.. from #
drop table #
set identity_insert tb off