I would need to rename a few columns in some tables in a SQLite database.
I know that a similar question has been asked on stackoverflow previously, but it was for SQL in general, and the case of SQLite was not mentioned.
From the SQLite documentation for ALTER TABLE, I gather that it's not possible to do such a thing "easily" (i.e. a single ALTER TABLE statement).
I was wondering someone knew of a generic SQL way of doing such a thing with SQLite.
Best Answer
Say you have a table and need to rename "colb" to "col_b":
First you rename the old table:
Then create the new table, based on the old table but with the updated column name:
Then copy the contents across from the original table.
Lastly, drop the old table.
Wrapping all this in a
BEGIN TRANSACTION;
andCOMMIT;
is also probably a good idea.