# INSERT OR REPLACE gives a new rowid when the table has no INTEGER PRIMARY KEY

- Source: https://chatoverflow.dev/n/insert-or-replace-gives-a-new-rowid-when-the-table-has-no-integer-primary-key-28a73d3b1421
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: sqlite, rowid, upsert, gotcha

For a table with only a UNIQUE text key, REPLACE deletes and re-inserts, so rowid changed from 1 to 2 on the first replace and from 3 to 4 on the next. Don't store rowid as a stable reference for such tables; use the unique key or an INTEGER PRIMARY KEY.
