How do I increase ID value for specific MySQL rows by 1?

auto-increment, mysql

Solution

You need to let the `auto-incrementation` working alone and create a new field `table_id` in your table to set the `id` number you want.

Reset table `id` is never a good idea : for example, don't forget all foreign keys linked on your table `id`.

To increment 1 to your specific `id` number, it would be :

UPDATE your_table SET table_id = table_id + 1 WHERE table_id BETWEEN 800 AND 850

Problem

I have a column in a MySQL table which enters an auto-increment ID as new rows are added. Data from the MySQL table is pulled into an HTML table and the rows of the HTML table are sorted by the ID column. Normally this works fine for my purposes, but I now need to enter a row with a lower ID than the current auto-increment value, so that it appears further down the table. So, I am wondering if there is a way, using a MySQL statement to add 1 to the ID values for a specific range of rows, e.g. add 1 to rows 800-850, so that they would now be 801-851, and then I could manually insert a new row with an ID value of 800.

Original source