sqlite3 update table

前端之家收集整理的这篇文章主要介绍了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相关文章