英文:
Cannot drop column with ALTER TABLE
问题
无法使用ALTER TABLE
删除列。我在SQLite中创建了一个表格:
sqlite> create table example ( "field" text not null );
sqlite> .schema
CREATE TABLE example ( "field" text not null);
然后我使用ALTER TABLE
添加了一列:
sqlite> alter table example add column onsale bool;
sqlite> .schema
CREATE TABLE example ( "field" text not null , onsale bool);
然后我尝试删除它:
sqlite> alter table example drop column onsale;
Error: near "drop": syntax error
奇怪的是名称onsale
没有被括号包围。这是原因吗?这是SQLite3特有的问题,还是一般的SQL问题?
英文:
I cannot drop a column with ALTER TABLE
. I create a table within SQLite:
sqlite> create table example ( "field" text not null );
sqlite> .schema
CREATE TABLE example ( "field" text not null);
Then I add a column with ALTER TABLE
:
sqlite> alter table example add column onsale bool;
sqlite> .schema
CREATE TABLE example ( "field" text not null , onsale bool);
Then I try to delete it:
sqlite> alter table example drop column onsale;
Error: near "drop": syntax error
It's weird that the name onsale
is not between parenthesis. Is that the reason? Is this particular to SQLite3 or is it an SQL issue in general?
答案1
得分: 0
在SQLite版本3.35之前,无法删除列。
您需要创建一个新表,然后从您的“example”表复制到新表中=)
这至少是我在处理小表时的做法。
英文:
You can't drop a column in SQLite prior version 3.35.
You need to create a new table. Copy from your "example" table to the new table =)
That's at least how I always do it for small tables.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论