无法使用ALTER TABLE删除列。

huangapple go评论65阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年6月12日 04:27:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76452396.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定