I am trying to find the best way to delete a column in SQLite. Here are the two ways I found:
From the official website http://www.sqlite.org/faq.html#q11:
BEGIN TRANSACTION;
CREATE TEMPORARY TABLE t1_backup(a,b);
INSERT INTO t1_backup SELECT a,b FROM t1;
DROP TABLE t1;
CREATE TABLE t1(a,b);
INSERT INTO t1 SELECT a,b FROM t1_backup;
DROP TABLE t1_backup;
COMMIT;
and from How to delete or add column in SQLITE? (which is also from the official website http://sqlite.org/lang_altertable.html):
1. create new table as the one you are trying to change,
2. copy all data,
3. drop old table,
4. rename the new one.
The first method uses a temporary table as the middle man to hold the values. The second method directly copies the values to the new table and renaming table name later. From a top level view, these are the only differences I see. Which one is more efficient? Is there an advantage choosing one over the other?
Is there any underlying information that I should take note of like rollback safe?