Resetting Autoincrement in Android SQLite

前端 未结 4 1737
隐瞒了意图╮
隐瞒了意图╮ 2020-12-31 10:53

I have this method which will remove all rows from a table but I also want it to reset the autoincrement so that when a new row is added it will start again. The SQL stateme

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-31 11:57

    Building on dldnh's answer:

    The following query will set seq to the largest value in the col identity column in the Tbl table, so there is no risk of violating constraints.

    UPDATE sqlite_sequence SET seq = (SELECT MAX(col) FROM Tbl) WHERE name="Tbl"
    

提交回复
热议问题