Modify SQLite table: Delete column
]question:
Try to delete a column from the SQLite database table using the following query:
ALTER TABLE table_name DROP COLUMN column_name;
However, it was not successful. What is the solution?
Answer:
In versions before SQLite 3.35.0 (2021-03-12), direct deletion of columns is not supported. To make such changes, a more complex approach is required:
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;
]
renew:
SQLite 3.35.0 and later now directly supports the DROP COLUMN clause, making it easier to delete columns from tables.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3