gpt4 book ai didi

sql - 从 SQLite 表中删除列

转载 作者:IT王子 更新时间:2023-10-29 06:16:48 29 4
gpt4 key购买 nike

我有一个问题:我需要从我的 SQLite 数据库中删除一列。我写了这个查询

alter table table_name drop column column_name 

但它不起作用。请帮助我。

最佳答案

更新:SQLite 2021-03-12 (3.35.0) 现在支持 DROP COLUMN。网站上的常见问题解答仍然过时。


发件人:http://www.sqlite.org/faq.html :

(11) How do I add or delete columns from an existing table in SQLite.

SQLite has limited ALTER TABLE support that you can use to add acolumn to the end of a table or to change the name of a table. If youwant to make more complex changes in the structure of a table, youwill have to recreate the table. You can save existing data to atemporary table, drop the old table, create the new table, then copythe data back in from the temporary 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 thistable. 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;

关于sql - 从 SQLite 表中删除列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5938048/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com