sqlite3 update table



You have two options. First,you could simply add a new column with the following:

ALTER TABLE {tableName} ADD COLUMN COLNew {type};

Second,and more complicatedly,but would actually put the column where you want it,would be to rename the table:

TABLE {tableName} RENAME TO TempOldTable;

Then create the new table with the missing column:

CREATE TABLE {tableName} (name TEXT, COLNew {type} DEFAULT {defaultValue}, qty INTEGER, rate REAL);

And populate it with the old data:

INSERT INTO {tableName} (name, qty, rate) SELECT name, rate FROM TempOldTable;

Then delete the old table:

DROP TABLE TempOldTable;

I'd much prefer the second option,as it will allow you to completely rename everything if need be.


http://stackoverflow.com/questions/4253804/insert-new-column-into-table-in-sqlite

相关文章

SQLite架构简单,又有Json计算能力,有时会承担Json文件/RES...
使用Python操作内置数据库SQLite以及MySQL数据库。
破解微信数据库密码,用python导出微信聊天记录
(Unity)SQLite 是一个软件库,实现了自给自足的、无服务器...
安卓开发,利用SQLite实现登陆注册功能