Page 1 of 1

Reseting auto increment field

Posted: Fri Oct 10, 2003 2:27 pm
by phpcoder
How to reset the value of auto increment field to 1 . i have id field in my table if i delete all record from that table and when i insert new record it assign next available id it doesnt start from 1 again so how 2 reset it to 1 .

Posted: Fri Oct 10, 2003 2:28 pm
by delorian
If you delete all records it is simple to drop table and create a new one :D

Posted: Fri Oct 10, 2003 2:29 pm
by murph
In the database click the empty button and it should empty the database and when you insert something it should start at 1.

Posted: Fri Oct 10, 2003 2:32 pm
by DuFF
Also, if you are using PHPMyAdmin you can actually set this by selecting the table and going into Options. There is an edit box with the auto_increment setting right next to it. Just change this to 1 and then click Go.

Posted: Fri Oct 10, 2003 2:32 pm
by Cruzado_Mainfrm
try

Code: Select all

ALTER TABLE tbl_name AUTO_INCREMENT = 1

Posted: Fri Oct 10, 2003 2:33 pm
by Draco_03
me i created a variable that will increment my Primary key

Code: Select all

<?php
while(odbc_fetch_row($queryexe)) 
    { 
    $varkey = odbc_result($queryexe, 1);  /*where 1 is in fact the field i need you might need to change it for 2 3 or whatever */
	}
	$var = $varkey;
if ($var == "NULL") {
$var == 1;
}else{
$var++;
}
?>
i use access db.. but you can change the syntaxe to fit mysql.. but me it works..

i dunno if i help ya but i tried :)

Posted: Fri Oct 10, 2003 2:44 pm
by phpcoder
murph wrote:In the database click the empty button and it should empty the database and when you insert something it should start at 1.
10x very much it works well 10x 4 ur help