Results 1 to 4 of 4

Thread: how to erase a id table in sql server

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    93

    how to erase a id table in sql server

    hi,
    i creating a aplication with sql server database and now i want distribute the aplication with the database that i created but i have registered some records to test the program and now i want reset the id for start again from 0
    there is any way to do that?
    and there is any program to generate a sql batch to creat the database too?
    thanks for your help
    bruno

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: how to erase a id table in sql server

    From the SQL help (books online - BOL)...

    The following example forces the current identity value in the Employee table in the AdventureWorks database to a value of 30.

    USE AdventureWorks;
    GO
    DBCC CHECKIDENT ('HumanResources.Employee', RESEED, 30)
    GO
    Creating the database from a script is a bit harder - first is this MS SQL Express or MS SQL 2000 or 2005??

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    93

    Re: how to erase a id table in sql server

    hi,
    i using sql server 2000 i will try the code that you say
    thanks for your help
    bruno

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: how to erase a id table in sql server

    Truncate Table also resets Identity columns but has some restrictions. You cannot execute Truncate Table if the table is being used in a relationship (ie foreign keys).

Posting Permissions

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



Click Here to Expand Forum to Full Width