業務需求:
test_info表中的一列主鍵自動遞增的xxid,由於中間使用測試數據的時候,插入了很多無關的記錄,刪除後,XXID不再連續。從新把XXID進行自動遞增的數字序列處理。
數據量:60000行。
數據庫:SQL server 2005
1、取消XXID的主鍵和遞增標識
2、把數據提取到中間表
select identity(int,1,1) as tid, xxid, htbh into #ttttt from test_info order by HTBH
select * from #ttttt order by xxid
3、更新目標表test_info的XXID
update test_info set xxid = tid from #ttttt where #ttttt.xxid = test_info.xxid
select * from test_info order by xxid
4、刪除中間表
drop table #ttttt
附:
複製表數據的命令
--如果表已經存在
insert into 新表 select * from 舊錶--如果不存在表
select * into 新表 from 舊錶