Closed Thread
Results 1 to 3 of 3

Thread: AutonumberID - reset?

  1. #1
    Barn Legend Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    1,522
    Rep Power
    5

    AutonumberID - reset?

    Hi All,

    Is there a way to reset the an autonumberID in sql2000? if so, will it change existing records or do I need to delete data then reset then populate table?

    Thanks!

  2. #2
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    This works in 2005, and probably in 2000 as well:
    DBCC CHECKIDENT('table', RESEED,0)

    The existing records are not affected, so you would need to either update the Key values or deleted the records.

    [edit] I should point out because it wasn't clear, that this will reseed the identity value regardless of whatever is in the table already. So, if your identity field is the primary key (and more are), the next insert will probably fail on a primary key violation (assuming that PK=1 is already in the table). An identity field itself does NOT ensure that the values will be unique.

    Also, you can not UPDATE the values in the identity field directly. If the records need to be preserved, they should be copied to a temp table and then inserted back once the identity has been reseeded.[/edit]
    Last edited by Wolffy; September 18th, 2009 at 05:09 PM.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  3. #3
    Barn Legend Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    1,522
    Rep Power
    5

    that gave me a heartattack...hehe...

    deleted data from table first then run that in sql analyzer and then added data back into table...w00t w00t...all is good.


Closed Thread

Similar Threads

  1. Reset value
    By guddu in forum JavaScript Programming
    Replies: 0
    Last Post: November 19th, 2008, 06:27 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO