views:

185

answers:

3

Hi all; In my table tbphotos i had 100 recordes then i deleted all,now that i want restart data entry i see that my primary key doesn't start from 1 , but it start from 101 ,is there any way? -I work in "Mysql administrator"

thanks

+3  A: 

alter table foo AUTO_INCREMENT = 1

Donnie
thanks for all answers.
Kaveh
+2  A: 

You can reset the auto-increment like this:

ALTER TABLE tablename AUTO_INCREMENT = 1

But if you are relying on the autoincrement values, your program is very fragile. If you need to assign consecutive numbers to your records for your program to work you should create a separate column for that, and not use a database auto-increment ID for this purpose.

Mark Byers
A: 

If you use TRUNC instead of manually deleting records, your primary key will be reset.

Vladimir Kocjancic
TRUNCVATE does not reset the auto_id on INNODB tables
PHP-Steven