开发者

How to make sure SQLite never create a row with the same ID twice?

开发者 https://www.devze.com 2023-03-27 15:47 出处:网络
I have a SQLite table that looks like this: CREATE TABLE Cards (id INTEGER PRIMARY KEY, name TEXT) So each time I create a new row, SQLite is going to automatically assign it a unique ID.

I have a SQLite table that looks like this:

CREATE TABLE Cards (id INTEGER PRIMARY KEY, name TEXT)

So each time I create a new row, SQLite is going to automatically assign it a unique ID.

However, if I delete a row and then create a new row, the new row is going to have the ID of the previously deleted row.

How can I make sure it doesn't happen? Is it possible to somehow force SQLite to always give really unique IDs, that are even different from previously deleted r开发者_高级运维ows?

I can do it in code but I'd rather let SQLite do it if it's possible. Any idea?


Look at autoincrement (INTEGER PRIMARY KEY AUTOINCREMENT). It will guarantee this and if the request can't be honored it will fail with SQLITE_FULL.

0

精彩评论

暂无评论...
验证码 换一张
取 消