Home >Database >Mysql Tutorial >How to Properly Reset an Auto-Incrementing Primary Key in SQLite?
Reset SQLite auto-increment primary key
Resetting auto-incrementing primary key fields can be tricky when using SQLite. A common misconception is that the DELETE FROM tablename
command is sufficient. However, it only deletes the data and the auto-increment function continues from the previous endpoint.
To properly reset your primary key, consider the following steps:
<code class="language-sql">DELETE FROM your_table; DELETE FROM sqlite_sequence WHERE name='your_table';</code>
SQLite auto-increment mechanism
SQLite maintains a special table (sqlite_sequence
) to track the maximum ROWID assigned to each table. SQLite initializes this table when creating the AUTOINCREMENT column. Modifying the sqlite_sequence
table may break the key generation algorithm, so caution is recommended.
Additionally, the following resources may be helpful:
The above is the detailed content of How to Properly Reset an Auto-Incrementing Primary Key in SQLite?. For more information, please follow other related articles on the PHP Chinese website!