Results 1 to 4 of 4

Thread: how reset the id of mysql?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2007
    Posts
    20

    how reset the id of mysql?

    hi,
    there is any way to reset the id of mysql?
    thanks for your help

  2. #2
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: how reset the id of mysql?

    Yes use the TRUNCATE SQL query e.g.

    TRUNCATE TABLE "table_name"

    Obviously this will delete all the data in the table aswell as reset the id.
    Chris

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: how reset the id of mysql?

    There are two other ways that don't truncate any table data.

    Code:
    -- Reset the increment ID of a table to its highest existing value + 1
    ALTER TABLE table_name AUTO_INCREMENT=1
    
    -- Override the automatic insert ID
    SET insert_id=n
    INSERT INTO table_name ...

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: how reset the id of mysql?

    You should never need to reset the auto increment ID unless you intend to remove the data, as each record is designed to be unique. This could destroy the integrity of the tables - especially if it is linked to others.

    The best thing to do is plan ahead. You can use any integer type as an auto increment field, these are:

    1bit (boolean), 8bit (byte), 16bit (small), 24bit (medium), 32bit (int), 64bit (big)

    A standard integer (32 bits) will give you a total of 4,294,967,296 unique records. You should be using this type if you are using a 32bit operating system as it is fastest.

    If you think you might need more than 4.2 million records, you can use the big int, giving you a total of 18,446,744,073,709,551,615 unique records. I worked out that populating your database with one record every second; it would take over 4105 billion years to exahaust that number.

    Assuming the universe lasts that long you will still have to find space to store the 128 exabytes of data your auto increment field alone will require. Not to mention all the other fields.

    In short a 32bit integer should be more than adequate for the life time of the majority of database tables.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

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