Solved how to reset auto increment id of column in data base table of sqlite browser ?
-
@Qt-embedded-developer Try to delete the whole table and create it again. Simply deleting all data will not reset auto increment id.
-
@Qt-embedded-developer said in how to reset auto increment id of column in data base table of sqlite browser ?:
delete all data from table not a table
If it is a SQLite DB, you have also to reset to Autoincrement ID from the sequence table:
delete from your_table; delete from sqlite_sequence where name='your_table';
-
@KroMignon said in how to reset auto increment id of column in data base table of sqlite browser ?:
delete from sqlite_sequence where name='your_table'
this logic does not work
-
@Qt-embedded-developer said in how to reset auto increment id of column in data base table of sqlite browser ?:
this logic does not work
Well, you should show code and tell what exactly "does not work"...
Any errors? -
@Qt-embedded-developer I seriously hope you have replaced
'your_table'
with the actual name of your table. -
@J-Hilk yes i have replace that name with my table name
-
@Qt-embedded-developer said in how to reset auto increment id of column in data base table of sqlite browser ?:
this logic does not work
How did you test if it works or not?
SQLite is a stateless DB, autoincrements are stored in "private" Sqlite tablesqlite_sequence
. If you delete the entries in this table, it will restart from 0.Extract from SQLite documentation:
SQLite keeps track of the largest ROWID using an internal table named "sqlite_sequence". The sqlite_sequence table is created and initialized automatically whenever a normal table that contains an AUTOINCREMENT column is created. The content of the sqlite_sequence table can be modified using ordinary UPDATE, INSERT, and DELETE statements. But making modifications to this table will likely perturb the AUTOINCREMENT key generation algorithm. Make sure you know what you are doing before you undertake such changes. The sqlite_sequence table does not track ROWID changes associated with UPDATE statement, only INSERT statements.
-
The sqlite_sequence table does not track ROWID changes associated with UPDATE statement, only INSERT statements.
thank you KroMignon
i used update query with delete from that's why auto increment id not get reset with delete from query
QString sSqliteQuery; QSqlQuery qQuery; sSqliteQuery = "DELETE FROM "+sDBTableName[DBTABLE_SURVEY];
#ifdef QDEBUG_ENABLE
pMainApp.ObjSettings.DebugStation(sSqliteQuery);
#endif
pMainApp.ObjDbOperations.ExecuteQueryFromString(sSqliteQuery, qQuery);
sSqliteQuery = "UPDATE sqlite_sequence SET seq = 0 WHERE name = "+sDBTableName[DBTABLE_SURVEY];
#ifdef QDEBUG_ENABLE
pMainApp.ObjSettings.DebugStation(sSqliteQuery);
#endif
pMainApp.ObjDbOperations.ExecuteQueryFromString(sSqliteQuery, qQuery); -
@Qt-embedded-developer said in how to reset auto increment id of column in data base table of sqlite browser ?:
i used update query with delete from that's why auto increment id not get reset with delete from query
I do not clearly understand if you still have a problem with AUTOINCREMENT reset?
Does it work now? -
@KroMignon Dear i have drop table and recreate it. it works for reset auto increment id