option to reset autoincrement value

Issue #382 new
Tech Comet created an issue

please run this code after “empty table”

UPDATE SQLITE_SEQUENCE SET SEQ=0

Comments (3)

  1. phpLiteAdmin repo owner

    ok. Some remarks:

    • UPDATE SQLITE_SEQUENCE SET SEQ=0 resets all primary keys (of all tables in the database). Instead, we should only reset the one of the table that has been emptied, i.e. use WHERE ”name”='TABLENAME'. Otherwise this could cause unexpected results.
    • I would rather delete the row than set the value to 0:
      DELETE FROM SQLITE_SEQUENCE WHERE “name”='TABLENAME'
    • Note that this should normally not be needed.

      • Either you want the values of this primary key to be unique over time, i.e. do not want to allow reuse. Then you should not reset the autoincrement value, because this will lead to reuse of key values.
      • Or you do not care if primary key values are reused. Then you should not use the AUTOINCREMENT keyword. SQLite autoincrements INTEGER PRIMARY KEY columns automatically anyways, no need for the AUTOINCREMENT keyword. The only change that this keyword does is: It makes sure keys are never reused. If this is what you want, you would be in the previous case. If you do not use the AUTONCREMENT keyword, then SQLite will automatically reuse keys, i.e. there is no need to reset anything (also, there is no row in SQLITE_SEQUENCE for this table in this case).
    • This should be an option that is not enabled by default.

    Read: https://sqlite.org/autoinc.html

  2. Former user Account Deleted

    From my point of view this should not be implemented att all into phpLiteAdmin.

    If anyone would like to reset autoincrement values there should be strong reason for this and the needed commands can be triggered manually like any arbitrary sql command using phpLiteAdmin.

  3. Log in to comment