How to update auto-increment field after removing a row?

user3894700

I have auto increment fields in mysql database, that is my id when I remove on of the my items the next field id is starting after deleted number.

For Example: my content from 1 to 100, when I remove these contents (from 1 to 100), and insert other contents, The id is 101, I need the id to be 1 and start from 1 again or start from the smaller number in MySQL id field

EDIT: I have a CMS , in CMS the user can delete some rows, and I need other auto increment update automaticaly

Mohammad Kermani

I think there is no option in MySQL to do this, but if you have a CMS and need to sorting auto-increment fields by MySQL, I know a better way that is fetching auto-increment fields value and put them in an array and then work with that array, for example This is your database table:

id  |  name  

and this is the value of your table:

25  | Ali
36  | Alex
37  | Reza
39  | Steven
40  | Mohammad

Then fetch this values and put them in array and then work for that from 0 to the end (count of fields on table):

for example You can have access to the each value what you want from 0 to end:

echo $array[0];

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SQL simulating Auto increment field

From Dev

AUTO_INCREMENT on UPDATE in MySql

From Dev

How do I make an auto increment integer field in Django?

From Dev

How to get id(Auto increment) of last row inserted

From Dev

Mongoose field how to auto increment

From Dev

How to update field when delete a row in laravel

From Dev

Update all values except auto-increment field using PHP / MySql / PDO

From Dev

MySQL Update command with auto increment

From Dev

how to instruct ecto to not create the auto increment id field?

From Dev

how to recalculate serial number in a html table after removing row by jquery

From Dev

How to retrieve the auto increment field name from a table?

From Dev

how to reset the value of a AUTO_INCREMENT row in a mysql table

From Dev

auto increment field in Peewee

From Dev

How can i have auto-increment field in nedb?

From Dev

How to stop a ++$i auto increment after a certain number

From Dev

How to update field all rows using auto increment?

From Dev

How to add auto_increment field to a table with huge data?

From Dev

MySQL rearange auto increment after row is deleted

From Dev

SQL simulating Auto increment field

From Dev

How to update field value to auto-increment field value?

From Dev

Reset auto_increment after deleting row

From Dev

Update all values except auto-increment field using PHP / MySql / PDO

From Dev

MySQL Update command with auto increment

From Dev

how to reset the value of a AUTO_INCREMENT row in a mysql table

From Dev

How to auto update the selected row in listview after save sucess in wpf mvvm

From Dev

How to improve query performance with auto increment field as primary key

From Dev

How to insert a row to an existing auto increment table in oracle?

From Dev

How to make auto-increment field in app maker from 5000

From Dev

How do we update without removing field of state? (in React / JavaScript)

Related Related

  1. 1

    SQL simulating Auto increment field

  2. 2

    AUTO_INCREMENT on UPDATE in MySql

  3. 3

    How do I make an auto increment integer field in Django?

  4. 4

    How to get id(Auto increment) of last row inserted

  5. 5

    Mongoose field how to auto increment

  6. 6

    How to update field when delete a row in laravel

  7. 7

    Update all values except auto-increment field using PHP / MySql / PDO

  8. 8

    MySQL Update command with auto increment

  9. 9

    how to instruct ecto to not create the auto increment id field?

  10. 10

    how to recalculate serial number in a html table after removing row by jquery

  11. 11

    How to retrieve the auto increment field name from a table?

  12. 12

    how to reset the value of a AUTO_INCREMENT row in a mysql table

  13. 13

    auto increment field in Peewee

  14. 14

    How can i have auto-increment field in nedb?

  15. 15

    How to stop a ++$i auto increment after a certain number

  16. 16

    How to update field all rows using auto increment?

  17. 17

    How to add auto_increment field to a table with huge data?

  18. 18

    MySQL rearange auto increment after row is deleted

  19. 19

    SQL simulating Auto increment field

  20. 20

    How to update field value to auto-increment field value?

  21. 21

    Reset auto_increment after deleting row

  22. 22

    Update all values except auto-increment field using PHP / MySql / PDO

  23. 23

    MySQL Update command with auto increment

  24. 24

    how to reset the value of a AUTO_INCREMENT row in a mysql table

  25. 25

    How to auto update the selected row in listview after save sucess in wpf mvvm

  26. 26

    How to improve query performance with auto increment field as primary key

  27. 27

    How to insert a row to an existing auto increment table in oracle?

  28. 28

    How to make auto-increment field in app maker from 5000

  29. 29

    How do we update without removing field of state? (in React / JavaScript)

HotTag

Archive