Skip to content Skip to sidebar Skip to footer

Don't Use Deleted Primary Keys

Insert id 1 and 2. Remove id 2. Insert new row, it gets id 2 instead of 3. How do I change this? I don't want to reuse primary keys. import sqlite3, os os.remove('mydatabase.db')

Solution 1:

From https://www.sqlite.org/autoinc.html:

If the AUTOINCREMENT keyword appears after INTEGER PRIMARY KEY, that changes the automatic ROWID assignment algorithm to prevent the reuse of ROWIDs over the lifetime of the database. In other words, the purpose of AUTOINCREMENT is to prevent the reuse of ROWIDs from previously deleted rows.


Post a Comment for "Don't Use Deleted Primary Keys"