- changed title to option to reset autoincrement value
option to reset autoincrement value
Issue #382
new
please run this code after “empty table”
UPDATE SQLITE_SEQUENCE SET SEQ=0
Comments (3)
-
repo owner -
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. useWHERE ”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 autoincrementsINTEGER PRIMARY KEY
columns automatically anyways, no need for theAUTOINCREMENT
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 theAUTONCREMENT
keyword, then SQLite will automatically reuse keys, i.e. there is no need to reset anything (also, there is no row inSQLITE_SEQUENCE
for this table in this case).
-
This should be an option that is not enabled by default.
Read: https://sqlite.org/autoinc.html
-
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.
- Log in to comment