top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Reseting the auto-increment number in a MySQL database using PHP

0 votes
664 views

I have a client where their next auto-increment number just jumped from 2300 to ********** for reasons not understood. They want it set back.

Options such as dropping the primary key and rebuilding the index is NOT possible -- this is a relational table thing. So, is there a way (programmatically) to set the next number in an auto-increment?

Something like:

alter table abc auto_increment = 2301;

Any ideas of why this happened?

posted Jun 26, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

3 Answers

+1 vote
 
Best answer

You can try this: *ALTER TABLE tbl AUTO_INCREMENT = 100;
Source: http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html

answer Jun 26, 2013 by anonymous
0 votes

holes in sequence of auto increment happen using transaction for insert new record but you don't commit transaction itself it seems that the autoincrement is incremented anyway at least this is my case.

answer Jun 27, 2013 by anonymous
0 votes

AUTO_INCREMENT => ONE OF THE COOL FEATURE

Suppose you have postid in your post table. AND you want that whenever anyone submit a post the postid gets incremented by one automatically.(without the user)

USER JUST SUBMIT THE POST or OTHER COLUMN FIELD . But postid is incrementing by itself whenever anyone enters. You can implement it on a primary key column.


Resenting the auto_increment :

#alter table abc auto_increment = 2301; 
#TRUNCATE TABLE table_name

(WARNING Truncate command will remove all the data from the table)

Go to table=>Operation=>Enter Auto_Increment value

answer Aug 16, 2014 by anonymous
Similar Questions
+2 votes

I have a date field on an html form that users may leave blank. If they do leave it blank I want to write the date 01/01/1901 into the mysql table. How can I accomplish this and where in my .php script file should I put the code?

...