0

我想从我的 sqlite 数据库中删除一列。我为此应用以下查询:

ALTER TABLE table_name DROP COLUMN column_name;

但它给了我以下错误:

near "DROP": syntax error

是 sqlite3 数据库中支持的删除列。如果是,那么这个查询有什么问题?

4

1 回答 1

0

我尝试使用ALTER TABLE User DROP COLUMN firstName;只是为了查看它是否可以正常工作,但根据此处的文档,支持的唯一功能是 DROP TRIGGER、INDEX、TABLE 和 VIEW

我真的怀疑是否支持 DROP COLUMN。

编辑:在第 11 点,可以找到问题的答案,内容如下

SQLite 具有有限的 ALTER TABLE 支持,您可以使用它来将列添加到表的末尾或更改表的名称。如果要对表结构进行更复杂的更改,则必须重新创建表。您可以将现有数据保存到临时表中,删除旧表,创建新表,然后将数据从临时表中复制回来。

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;
于 2012-06-06T07:18:49.167 回答