我試圖用FMDB刪除從人柱姓氏,如何使用FMDB刪除特定表格的列?
let query = "ALTER TABLE Persons DROP COLUMN last_name;"
try FMDBHelper.database.executeUpdate(query, values: nil)
但帶有錯誤
DB Error: 1 "near "DROP": syntax error".
我試圖用FMDB刪除從人柱姓氏,如何使用FMDB刪除特定表格的列?
let query = "ALTER TABLE Persons DROP COLUMN last_name;"
try FMDBHelper.database.executeUpdate(query, values: nil)
但帶有錯誤
DB Error: 1 "near "DROP": syntax error".
SQLite不支持DROP列ALTER TABLE。
您只能重命名錶格並添加列。
如果您需要刪除列,請創建一個新表,在那裏複製數據,刪除舊錶並將表重命名爲其名稱。
請注意,我舉報過你的問題可以被複制,我會提供一個答案,使之更加清晰。
我認爲你是缺少一個點,那就是:在FMDB是(作爲其回購的描述中提到):
This is an Objective-C wrapper around SQLite
請記住,因爲FMDB是建立在SQLite的頂部,它是而不是從庫本身的限制;它與SQLiteALTER TABLE
的工作方式有關。
的SQLite ALTER TABLE
聲明僅限於重命名一張桌子和add
一個新列到所需的表:
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.
http://www.sqlite.org/lang_altertable.html
爲了實現你在尋找:
您可以查看Delete column from SQLite table的回答。
[如何刪除或添加列在SQLITE中?](https://stackoverflow.com/questions/8442147/how-to-delete-or-add-column-in-sqlite) –
@AhmadF FYI我正在嘗試SWIFT-FMDB。 – Amit