Turn: http://www.open-open.com/lib/view/open1347440993944.html
Android applications may inevitably deal with SQLite. With the continuous upgrading of applications, the original database structure may no longer adapt to new features. At this time, the structure of the SQLite database needs to be upgraded. SQLite provides the alter table command, allowing you to rename or add new fields to an existing table, but cannot delete fields from the table.
You can only add fields at the end of the table. For example, you can add two fields to subpartition:
1 alter table subpartition add column activation blob;
2 alter table subpartition add column key blob;
In addition, if you encounter complex modification operations, such as data transfer while modifying, You can execute the following statement in a transaction to modify the table.
1. Change the table name to a temporary table.
Alter table subpartition Rename to _ temp _ subpartition;
2. Create a new table
Create Table subpartition (orderid varchar (32) Primary key, username varchar (32) Not null, productidvarchar (16) Not null );
3. Import Data
Insert into subpartition select orderid, "", productid from _ temp _ subpartition;
Or
Insert into subpartition () Select orderid, "", productid from _ temp _ subpartition;
* Note that double quotation marks (") are used to supplement data that does not exist.
4. delete a temporary table
Drop table _ temp _ subpartition;
The above four steps can be used to migrate the old database structure to the new database structure, and ensure that the data will not be lost due to the upgrade.
Of course, you can also create a temporary table to reduce fields.
Attached example: ormlitetest.zip