Jump to content

[SOLVED] auto incrementing record not resetting upon delete command???


Recommended Posts

Hi I am using ID as a auto incrementing primary key  however if i goto the mysql command line and issue the command ....delete from myTable; then everything is deleted from the table but the ID property slot doesn't return to 1 how do i force it to return to 1?

well the table is a test table and I use where statements using the ID field instead of username for building generic modular scripts. so when i clear out the table using the delete command the ID picks up where it left off ....i want it to start over at  0 or 1 ....*shrugs* whichever it uses.

Use - TRUNCATE [table][tr][td] tbl_name

 

TRUNCATE TABLE empties a table completely. Logically, this is equivalent to a DELETE statement that deletes all rows, but there are practical differences under some circumstances.

 

For InnoDB before version 5.0.3, TRUNCATE TABLE is mapped to DELETE, so there is no difference. Starting with MySQL 5.0.3, fast TRUNCATE TABLE is available. However, the operation is still mapped to DELETE if there are foreign key constraints that reference the table. (When fast truncate is used, it resets any AUTO_INCREMENT counter. From MySQL 5.0.13 on, the AUTO_INCREMENT counter is reset by TRUNCATE TABLE, regardless of whether there is a foreign key constraint.)

 

Also, you and your coding should not care what the values are (or that there will be gaps when records are deleted.)

yeah absolutely i was asking this question more for informational purposes than for practical purposes....you answered my question and cleared my confusion................... thanks....this is a really great forum.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.