How to reset identity seed in Sql Azure

前端 未结 3 1355
遇见更好的自我
遇见更好的自我 2020-12-07 00:46

I have tried the following in order to reset my Identity Seed of a column:

DBCC CHECKIDENT (\'dbo.Stuff\', RESEED, 0)

This does not work in

3条回答
  •  心在旅途
    2020-12-07 01:23

    I have recently come up against this problem myself. I resolved it by inserting and deleting items in the table until I reached the desired seed value.

    In the example below, this will reseed the Users table so the next new item will have Id of 3500.

    BEGIN TRANSACTION
    GO
    
    DECLARE @max_id int
    
    SELECT @max_id = max([Id]) FROM users
    
    WHILE (@max_id < 3499)
    BEGIN
        INSERT INTO Users (Username, Password) VALUES ('','')
        SELECT @max_id = max([Id]) FROM Users
        DELETE FROM Users WHERE [Id] = @max_id
    END
    
    COMMIT
    

    Hope this helps.

提交回复
热议问题