如何在 sqlite 2 数据库表中添加列
如何向具有与其关联的数据和索引的现有 sqlite 2 数据库表添加附加列。
似乎sqlite2 中不提供alter table SQL?
How do I add an additional column to an existing sqlite 2 database table that have data and indexes associated with it.
It seems like the alter table SQL for that is not available in sqlite2?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
来自SqLite FAQ:
SQLite 具有有限的 ALTER TABLE 支持,您可以使用它来添加列添加到表的末尾或更改表的名称。 如果要对表结构进行更复杂的更改,则必须重新创建表。 您可以将现有数据保存到临时表,删除旧表,创建新表,然后将数据从临时表复制回。
例如,假设您有一个名为“t1”的表,其中包含列名称“a”、“b”和“c”,并且您想要从此表中删除列“c”。 以下步骤说明了如何完成此操作:
From the SqLite FAQ:
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.
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:
可能不是——sqlite3 已经发布有一段时间了。 您必须按照您想要的方式使用该表创建另一个数据库,并将数据复制到其中。 或者,创建一个新表,复制数据,删除原始表并替换为新表。
It might not be -- sqlite3 has been out for a while. You'll have to create another DB with the table the way you want it and copy the data to it. Or, create a new table, copy the data, drop the original and replace with the new one.
不要忘记 DROP TABLE 也会删除关联的触发器。
在修改表之前,使用命令
转储所有将被删除的当前语句,包括需要重新创建的触发器。
干杯,
埃利克森
Don't forget that DROP TABLE drops also associated TRIGGERs.
Before you are going to modify the table use the command
that will dump all the current statements that will be dropped including the TRIGGERs that you need to re-create.
Cheers,
Elixon
你不知道。 不支持对表进行重大修改。
您需要做的是:
You don't. Non trivial modification of tables is not supported.
What you would need to do is: