DBCC CHECKIDENT Sets Identity to 0

前端 未结 10 1332
长发绾君心
长发绾君心 2020-12-07 21:55

I\'m using this code to reset the identity on a table:

DBCC CHECKIDENT(\'TableName\', RESEED, 0)

This works fine most of the time, with the f

10条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 22:20

    Simply do this:

    IF EXISTS (SELECT * FROM tablename)
    BEGIN
        DELETE from  tablename
        DBCC checkident ('tablename', reseed, 0)
    END
    

提交回复
热议问题