How to update KEY_ROWID after deleting a row in SQLite database

前端 未结 2 1954
离开以前
离开以前 2021-01-21 14:19

How can I update the KEY_ROWID number in SQLite database after deleting a row from the database? CASE 1: For example, if I have five rows in the database, maximum KEY_ROWID is

2条回答
  •  失恋的感觉
    2021-01-21 15:07

    You can reset the sequences if you're deleting all data;

    DELETE FROM test;
    DELETE FROM sqlite_sequence WHERE name='test';
    

    As for renumbering primary keys when there is still data in the table, I'd sincerely advise against it, since any foreign keys that reference your table will be broken.

提交回复
热议问题