Can Reset The Id Auto Increment? - phpMyadmin

Pages: 1, 2
free web hosting

Read Latest Entries..: (Post #11) by iGuest on Aug 13 2008, 11:52 AM. (Line Breaks Removed)
I think the best way is, backup you database except the id table in one file, backup structure in other file, run the structure first, then run the database file.Goodluck
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Can Reset The Id Auto Increment? - phpMyadmin

badinfluence
hi,
Can we reset the id auto increment in the mysql database using by phpMyadmin?
let's say the shoutbox. the id #number table.. somehow i deleted some rows.. and i wanted to re-order/reset the id number acendingly in order rather than skip out..
thks


Reply

SystemWisdom
I don't think you can do that using phpMyAdmin, or even SQL for that matter, but you could write a PHP script to do that for ya...
Make a query like:

Select ID from <table> order by ID

then use a while/for loop to iterate through the results, and update each row with a new number for the ID.. you could use a PHP variable to track the current ID number, and increment it with each loop...

Update <table> set ID=???

Should work.. Although I have never tried manually updating an auto_increment field.. come to think of it, it seems pointless to adjust it, since it is dealt with internally anyway, and the actual value should never affect your script...

If that doesn't work, and you still need to sort them, try adding another field to the DB table, like a sort-order field..

Reply

tigen28
Please be warn that this is the manual-intensive-labor way, but no thinking require.

If you want to change any field in the table and do not mind changing only 1 field at a time, you can always go to php admin.

Then, select your database.

Next, click on the "table" you want to modify.

Last find the field and click edit; so basicially, click on field of a time and edit.

Hopefully, you don't have much entries in that table; otherwise, I highly unrecommend this route.

Well, hope it helps.

Reply

badinfluence
QUOTE(SystemWisdom @ Sep 8 2005, 08:44 AM)
I don't think you can do that using phpMyAdmin, or even SQL for that matter, but you could write a PHP script to do that for ya...
Make a query like:
Select ID from <table> order by ID
then use a while/for loop to iterate through the results, and update each row with a new number for the ID..  you could use a PHP variable to track the current ID number, and increment it with each loop...
Update <table> set ID=???
*



yes, System that's perfect and exactly true. Thanks for that trick. Indeed a littol risky humm.. phpMyAdmin should do that function by default. See whether i can request the feature about that on their sourceforge site.

this is the old and null way tongue.gif backup and re-construct laugh.gif

Thanks System and tigen for discussing this,

 

 

 


Reply

beeseven
I asked about this a while ago. A quick and easy way to set the next ID is this:
CODE
ALTER TABLE [tablename] AUTO_INCREMENT = [number]

where [tablename] is the name of the table and [number] is the next ID. I'm not sure of a quick way to change other, existing IDs, though.

Reply

p_a
It would be better not to do reorder of ID fields anyway. I do not want even to show them in my forms, grids. Maybe the new numbered field would be the best way to solve it.

Why shoud everybody avoid changing ID fields? Simply because of possibility of having relations in database between tables. ID fields sometimes have their main role in relations and playing games with them will make a mess. I would never do it.


Reply

csmith
This is a pretty primitive solution, but after you delete the rows which you wish to remove from the table, you could export the remaining rows into either a .csv file. In this subsequent excel file you could remove the first column which contains the id, save this file, and then re-import this back into your database table (you should click on the option of over-writing rows in this table which have the same id/primary key value as a row in the excel file), or re-import into a new table. The ids will be automatically re-set without any numbers skipped - it should not take too long, plus you should not lose any data in the process

Reply

sobhan
I don't think you can reset, you can only change value in phpMyAdmin.

Reply

najib
I know it's a zombie post, but I thought I'd give my part nonetheless.

CODE

ALTER TABLE `tablenamegoeshere` AUTO_INCREMENT =0


The above will reset the auto_increment to the lowest value. So everytime an entry is removed, drop any remaing ID's that are larger than the current entry by one, then query the database with the exact line above and you wont have any problems.

Sweet! ph34r.gif

Reply

iGuest
ALTER TABLE `tablenamegoeshere` AUTO_INCREMENT =0
Can Reset The Id Auto Increment?

Replying to najib
It's not a zombie post! Thanks! Saved a lot of time! :)

Reply

Latest Entries

iGuest
I think the best way is, backup you database except the id table in one file, backup structure in other file, run the structure first, then run the database file.
Goodluck

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Pages: 1, 2
Recent Queries:-
  1. reorder reset mysql autoincrement table - 0.80 hr back. (1)
  2. mysql update auto_increment fields - 2.37 hr back. (1)
  3. auto insert id reset - 5.29 hr back. (1)
  4. phpmyadmin auto increment - 13.18 hr back. (1)
  5. add ascending id each loop php - 13.98 hr back. (1)
  6. change autoincrement after delete in mysql - 14.81 hr back. (1)
  7. how to alter to auto increment column in sql 2005 - 14.90 hr back. (1)
  8. mysql id auto increment resetten - 15.34 hr back. (1)
  9. reset id field in access database - 16.13 hr back. (1)
  10. autoincrement reset to 1 after deleting columns - 16.36 hr back. (1)
  11. php mysql reset auto_increment - 17.12 hr back. (1)
  12. mysql autoinc phpmyadmin - 18.48 hr back. (1)
  13. mysql autoincrement reset - 18.61 hr back. (1)
  14. database id auto increment edit - 20.41 hr back. (1)
Similar Topics

Keywords : reset, id, auto, increment, phpmyadmin

  1. Delete Problem With Id
    Id as auto_increment, and identifier for a row (4)
  2. Phpmyadmin Login Problem!
    (1)
    I have easyphp. But i can not log when i go to phpmyadmin. I directly enter the page. But i think i
    should normally have to log in before enter that page. What should i do to configure the access to
    phpmyadmin? Thank for help....
  3. Auto Pruning An Sql Database With Php
    How can i do this? (4)
    Hey all. Now i have a DB, an SQL DB, and i need to auto prune the data there to delete rows lder
    than a certain time, lets say 2 months for now, the question is how do i do this? The obvious thing
    is just to add a field which is the numerical representation of the month when the data is entered
    and every time the DB is accessed it will check this number against the current month,in a numerical
    format, and if the difference is two or greater that row is deleted, so if the month is January, it
    would be O1 and if the current month is march then it would be O3 and the diff....
  4. Error Importing Sql Query Via Php
    Works in PHPmyAdmin (6)
    CODE     function sql()     {         $fp =
    fopen("sql.sql","r");         $sql =
    fread($fp,filesize("sql.sql"));         fclose($fp);
            return $sql;     } Thats $this->sql and here is the other source CODE
    function insert_sql()     {     if($_GET['insert'])  {
            $template = new template;         $db = new db;
            $db->connect();         $query = $this->sql();       ....
  5. Phpmyadmin And Php And Mysql
    tutorial (0)
    hi i think phpmyadmin is nice script (3rdparti) to learn php and mysql , you can add database and
    then make tabel with rows and columns then you can customise (search , show rows , show columns ,
    add rows , delete rows) tabel in phpmyadmin when you are customise phpmyadmin , this script show you
    php code . you can use this code for browse in database . for example : showing tabel : CODE
    SELECT * FROM `tabelname` LIMIT 0 , 30 searching : CODE SELECT `columns`
    FROM `tabel` LIMIT 0 , 30 you can use with while loop showing Ascending....
  6. Help Installing Phpmyadmin ..
    (2)
    i've installed php and mysql to my computer and i want to install PhpMyAdmin , (i have apache) ,
    i tried to find how to confure it , and it says Create the file config.inc.php in the main
    (top-level) directory , i dont know how to create that file..can some one tell me how i can confure
    that config file ?? and how i can run php in safe mode ?....
  7. Requesting Auto Generating Id Tag In Php Code
    Php Coding (2)
    Hello...I'm designing a website in PHP where ppl can submit their links for "cool sites".
    Anyway, when somebody submit's a link to a website for example "http://www.google.com" it
    creates an id such as "index.php?id=1134411593". I dont want the links to be converted into
    id's. I want it to remain as "http://www.google.com". I have the following coding on
    ( echo " ). I'm a novice. Please Help!!!!
    Thanks... Plus I also want to add the date on when the link was submitted. Please follow our foru....
  8. Suppressing Mysql Error In Php
    How to suppress auto generated mysql err (4)
    I am testing my website on my local machine. It is still in development stage and I am using
    php/mysql. If there is a mysql connection error, I am checking for the connection variable and
    displaying a proper error message. But even before it displays my error message, it displays an
    error message on browser thrown by mysql (MySQL Connection Failed: Access denied for user). Can I
    suppress this message and display only my message?....
  9. Adding Users To Databases Using Phpmyadmin
    (2)
    I am running my own apache server with PHP and MySQL, with phpMyAdmin on my own computer, to test
    things locally. I know how to create databases and how to create users, but how can I add a user to
    a database?....
  10. Increment A Mysql Column
    how to increment a MySQL column one unit (7)
    Hi, I have a column in a MySQL table which contains a counter of the views of the object described
    by this table. I would like to increment this value by one everytime the object is viewed. Obviously
    came into my mind the possibility of retrieving the value of this field, store it in a variable
    increment this value by one and perform an UPDATE query again with this new value. My question is if
    there is a MySQL option to update the field with its actual value plus an unit increment. I hope you
    understand the issue.....
  11. About Set Permisstions....
    auto set it, how? (4)
    I have some problem about set permissions by automatic.. for example... I created txt file with
    php... but when my file was added to server(trap17), it always set to 644 and i want to set it to
    666 . Anybody help me... PLEASE /biggrin.gif' border='0' style='vertical-align:middle'
    alt='biggrin.gif' /> ....

    1. Looking for reset, id, auto, increment, phpmyadmin

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for reset, id, auto, increment, phpmyadmin

*MORE FROM TRAP17.COM*
advertisement



Can Reset The Id Auto Increment? - phpMyadmin



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE