Reset Identity PK field

  • Hi,

    How to reset PK identity column to 0 value?

    Regards,

    GB

  • If you want to reset an identity range then

    DBCC CHECKIDENT('YourTable',RESEED,0)

    If you want to explicitly add a record that over rides the identity then

    SET IDENTITY_INSERT dbo.YourTable ON

    INSERT Yourtable(PKField,OtherFields) VALUES (0,Yourvalues)

    SET IDENTITY_INSERT dbo.YourTable OFF

  • Hi David,

    Thanks for the quick help. This solves my problem

    Regards,

    GB

  • If the table is empty, TRUNCATE TABLE user.tablename will do it as well.

  • TRUNCATE works on empty table: this is also helpful. Thanks for this trick too.

    Regards, GB

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply