iOS Question iSQLite change integer primary key.

MitchBu

Well-Known Member
Licensed User
Longtime User
I have a table where I deleted several records. As a result, the primary key has holes. For instance 1,2,3, then 5,6,7 and so on.

I want to reorder the primary key, so now it goes as 1 2 3 4 5 6.

Here is the structure of the table:
ID INTEGER PRIMARY KEY, Date TEXT, Number TEXT, Payee TEXT, Memo TEXT, CheckMark TEXT, Amount TEXT, Balance TEXT

Is there any way to change the ID integer primary key so I can reorder it ?

TIA :)
 

aeric

Expert
Licensed User
Longtime User
I just checked SQLite related websites. It is not possible to drop the column and add primary key column. You will need to create a new temporary table, copy the data from the old table, drop the table then rename the new temporary table to the old table name. If you are not doing it by SQL syntax, using software like DBBrowser may simplifies the job.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
If the table stores transactions, you may not want to delete any records. Just add a column for void and set it as true if the sales is cancelled then filter the records for void equals false for actual sales.
 
Upvote 0
Top