quick newbie auto increment question

  • Sorry probably been asked a thousand times, i tried a search on this forum and couldn't find it so

    I have a database with a int auto increment primary field, all of the data has been deleted. How do i reset the auto increment field back to 1?

    Thanks

  • DBCC CHECKIDENT (TableName , RESEED, 0)

     


    * Noel

  • truncating the table has the same effect

    set nocount on

    if object_id('idt') is not null

    drop table idt

    go

    create table idt(

    col1 int identity(1,1) primary key )

    go

    insert into idt default values

    select * from idt

    truncate table idt

    insert into idt default values

    select * from idt

    set nocount off

    col1

    -----------

    1

    col1

    -----------

    1

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Excellent! Thanks noeld & Frank for the fast replys

  • No problem

    Btw, there is no need to excuse to asking a question, methinks. There is only a need to excuse for a bad answer.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

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

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