4 ms·
Following up again, today I tried adding a primary key to a table in sqlite and didn't figure it out. I revisited the sqlite docs and found https://sqlite.org/f
by gwynforthewyn 2y ago
Following up again, today I tried adding a primary key to a table in sqlite and didn't figure it out. I revisited the sqlite docs and found https://sqlite.org/faq.html#q11 https://sqlite.org/faq.html#q11, showing that the alter statement is restricted to add, rename and drop.
It _does_ seem like you can add a primary key later in mysql and postgres, but I don't see any way to accomplish that in sqlite.
- changing1999 2y agoOh that's very interesting. I am actually using a UI called "DB Browser for SQLite" and checking its logs shows that when I add a PK, it actually creates a new temporary table, copies over all data from the old table, deletes the old table, and then renames the new table. So you were correct originally, it can't just add a PK. Thanks for following up!