SQL Server中重置或設定自動增長的序列

2021-10-04 10:59:00 字數 710 閱讀 5953

自動增長 序列,一般用來當做id 使用。

為了解決系統自增序列達到上限後系統出現問題,可以設定重置來解決。

dbcc checkident ('table_name', noreseed) 

-- 檢視當前表的序列的值,table_name為表名

dbcc checkident('table_name',reseed,1)

-- 重置當前表的序列值為1,不刪除表的資料。(注意:如果序列為主鍵,不刪除表的資料的時候,插入同id的資料時會出錯)

truncate table 'table_name'

-- 刪除表中的所有的資料的同時,將自動增長序列清零。

在這裡本人是處理系統的日誌問題

在sql server中建立作業,然後執行指定的命令。用到的 id 的型別是int 型別了,所以id的值自增到2147483647為最大值,所以在大於2000000000的時候將序列充值。

declare  @erplogid int

select top 1 @erplogid=id from tblerplog order by createdate desc

if @erplogid>2000000000

begin

dbcc checkident('tblerplog',reseed,10086)

end

sql server 重置自增

delete tb where id 100 dbcc checkident tb reseed,1 dbcc checkident tb reseed 其結果將 tb 表的自增種子設定為當前表裡標識列的最大值 再次增加資料就會繼續那個數字了 實測 建立測試環境 if object id tb is...

SQL Server重置INDETITY的開始值

identity 和scope identity 返回在當前會話中的任何表內所生成的最後乙個標識值。但是,scope identity 只返回插入到當前作用域中的值 identity 不受限於特定的作用域。建議謹慎使用 identity。ident current不受作用域和會話的限制,而受限於指定...

重置IE設定

退出所有程式,包括 internet explorer。單擊 開始 在 開始搜尋 框中鍵入 inetcpl.cpl 命令,然後按回車鍵開啟 inetnet 選項 對話方塊 單擊 高階 選項卡。在 重置 internet explorer 設定 下,單擊 重置 然後再次單擊 重置 您也可以勾選 刪除個...