DBCC CHECKIDENT RESEED — is new value required?

前端 未结 3 1290
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-12 10:26

All the documentation I read about reseeding suggests something along the lines of:

  1. SET @maxIdentityValue = (SELECT MAX(id) FROM tablename)
  2. <
3条回答
  •  伪装坚强ぢ
    2021-01-12 10:42

    As it is stated in MSDN, it is fairly enough to use just:

     DBCC CHECKIDENT('tablename', RESEED)  
    

    most of the time, however there are these two conditions where it will not work:

    • The current identity value is larger than the maximum value in the table.
    • All rows are deleted from the table.

    in which you have to go with they way that you mentioned (select max(id) and the rest), so why bother in the first place? :)

提交回复
热议问题