问题描述
我有一个问题:我需要从SQLite数据库中删除一列。我写了这个查询
I have a problem: I need to delete a column from my SQLite database. I wrote this query
alter table table_name drop column column_name
但它不起作用。请帮助我。
but it does not work. Please help me.
推荐答案
来自::
SQLite对ALTER TABLE的支持有限,可用于在$ item的末尾添加
列。表或更改表名。如果
想要对表的结构进行更复杂的更改,则
将不得不重新创建表。您可以将现有数据保存到
临时表中,删除旧表,创建新表,然后将
的数据从临时表中复制回来。
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.
例如,假设您有一个名为 t1的表,其列名为
a, b和 c,并且您要从此$ b $中删除列 c b表。以下步骤说明了如何完成此操作:
For example, suppose you have a table named "t1" with columns names "a", "b", and "c" and that you want to delete column "c" from this table. The following steps illustrate how this could be done:
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;
这篇关于从SQLite表中删除列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!