SQLite,ROOM 清空表数据并将自增量归零

 1.先清空表数据:

        delete from [tablename];


 2.当数据库中包含自增列时,会自动建立一个名为 sqlite_sequence 的表。这个表包含两个列:name和seq。name记录自增列所在的表(即tablename),seq记录当前序号(下一条记录的编号就是当前序号加1)。你可以通过如下方式将自增量归零:


        //1. 将表名为tablename的自增量置0
        update sqlite_sequence set seq = 0 where name = 'tablename'
        //2. 将表名为tablename的记录删除
        delete from sqlite_sequence where name = 'tablename'
        //3. 将sqlite_sequence表清空数据
        delete from sqlite_sequence

3.ROOM重置

@Query("DELETE FROM tablename")
void deleteAll();

@Query("UPDATE sqlite_sequence SET seq = 0 WHERE name = 'tablename'")
void resetPrimaryKey();

@Query("DELETE FROM sqlite_sequence WHERE name = 'tablename'")
void recordDeletion();

@Query("DELETE FROM sqlite_sequence ")
void wipeData();

你可能感兴趣的:(sqlite,数据库)