重置標識列為1,2,3,

2021-05-22 17:06:01 字數 338 閱讀 2604

--將原表除標識列外的所有列匯入臨時表,按標識列公升序排列(也可根據需要按任意方式排列)

select col1,col2,... into tablename_temp from tablename order by identitycolumn

--清空原表資料,重置當前標識為1

truncate table tablename

--將臨時表中資料插入原表,原表會根據插入順序自動生成標識列

insert into tablename select * from tablename_temp

--刪除臨時表

drop table tablename_temp

SQL Server重置自標識列 應用

1.重置標識方法 方法一 使用truncate truncate table name可以刪除表內所有值並重置標識值 但是表內的資料將丟失。方法二 你想要重置標識值 不刪除資料 採用下面方法即可 但是存在問題 1 dbcc checkident 表名 reseed,new value 重置新的標識值...

重置MSSQL的Identity標識列的值

當表中的記錄被全部刪除,但此時標識列的值越來越大的時候,如果不加以重置,它還會無休止的增長。可以用如下語句重置標識列 dbcc checkident table name new reseed value 引數 table name 是要對其當前標識值進行檢查的表名。表名必須符合識別符號規則。有關更...

SQL SERVER重置自動編號列 標識列

兩種方法 一種是用truncate truncate table name 可以刪除表內所有值並重置標識值 二是用dbcc checkident dbcc checkident table name reseed,new reseed value 如dbcc checkident bc pos re...