Reseting auto increment field

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Reseting auto increment field

Post 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 .
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post by delorian »

If you delete all records it is simple to drop table and create a new one :D
murph
Forum Commoner
Posts: 29
Joined: Fri Oct 03, 2003 1:28 pm
Location: washington

Post 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.
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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.
Cruzado_Mainfrm
Forum Contributor
Posts: 346
Joined: Sun Jun 15, 2003 11:22 pm
Location: Miami, FL

Post by Cruzado_Mainfrm »

try

Code: Select all

ALTER TABLE tbl_name AUTO_INCREMENT = 1
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post 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 :)
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post 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
Post Reply