如何在 SQLITE 中删除或添加列?
问题描述:
我想在sqlite数据库中删除或添加列
I want to delete or add column in sqlite database
我正在使用以下查询来删除列.
I am using following query to delete column.
ALTER TABLE TABLENAME DROP COLUMN COLUMNNAME
但它给出了错误
System.Data.SQLite.SQLiteException: SQLite error
near "DROP": syntax error
答
SQLite 支持有限的 ALTER TABLE 子集.SQLite 中的 ALTER TABLE 命令允许用户重命名表或向现有表添加新列.无法重命名列、删除列或在表中添加或删除约束.
SQLite supports a limited subset of ALTER TABLE. The ALTER TABLE command in SQLite allows the user to rename a table or to add a new column to an existing table. It is not possible to rename a column, remove a column, or add or remove constraints from a table.
您可以:
- 创建新表作为您要更改的表,
- 复制所有数据,
- 丢弃旧表,
- 重命名新的.