Domanda

I've got a SQLite database and a table that uses an autoincrementing int as the primary key. I've looked through the documentation and it seems that if I perform an INSERT AND REPLACE, it deletes then inserts a record when a duplicate is found.

This is fine, but the problem is that the autoincrementing key continues from where it left off, rather than starting from zero. This means that each time I run that query, the incrementing changes for the record. Is it possible to update the record without changing the primary key? One way I found that works is to delete the table and the primary key index, but that seems overkill and would likely result in a longer time as the table gets bigger.

È stato utile?

Soluzione

If the record exists, you could do an UPDATE on it. This will not change the primary key.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top