Reset identity value

  • I use below script to reset my identity values (after we do huge data copy to testing environment)

    declare @idvalue bigint

    select @idvalue = 0

    select @idvalue = max(Tid) + 1 FROM Tbl_identity_fld1

    dbcc checkident(Tbl_identity_fld1,RESEED, @idvalue)

    go

    Recently i noticed that when i my table is empty this query passes me error. Hence i will need to add a check if my table is empty then dont run this script..

    I have fbeen ailing to add this check at this year end 🙂 ..

    do i check for NULL

    do i check for 0..

    Help please

  • What error does it give you?

    If you want a check for empty table, just add an IF @@RowCount > 0 before the CheckIdent.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 2 (of 2 total)

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