Workaround for deleting Columns in SQLite
18 Sep 2015 #sqlIntro :
SQLite has limited ALTER TABLE
support that you can use to add a column to the end of a table or to change the name of a table. If you want to make more complex changes in the structure of a table, you will have to recreate the table. You can save existing data to a temporary table, drop the old table, create the new table, then copy the data back in from the temporary table.
From the docs.
It is not possible to rename a column, remove a column, or add or remove constraints from a table.
source : http://www.sqlite.org/lang_altertable.html
While you can always create a new table and then drop the older one.
I will try to explain this this workaround with an example.
Now you want to remove the column height
from this table.
Create another table called new_person
Now copy the data from the old table
Now Drop the person
table and rename new_person
to person
So now if you do a .schema
, you will see
So that’s how you insert and delete columns from an SQLite Database