Read many of the online information about database upgrades, field attributes, and learn about:
In fact, the database upgrade has two reliable methods, (1)
db.execsql ("ALTER TABLE test ADD COLUMN Age");
(2)
Db.begintransaction ();Db.execsql ("ALTER TABLE test RENAME to _test");Db.execsql ("CREATE TABLE Test (ID integer primary key autoincrement, PassWord VARCHAR () not NULL,"+ "UserName varchar (+) NOT NULL, age VARCHAR (+) is not null)");Db.execsql ("INSERT into Test SELECT ID," + str + str+ ", name, age from _test");Db.settransactionsuccessful ();Db.endtransaction ();
Because the database that comes with Android is used by a Sqliteopenhelper class, the OnCreate () is executed at the first call, where the database table is created
public void Onupgrade (sqlitedatabase db, int oldversion, int newversion) {} is called when the current version of the database is less than the new database version
You can upgrade the database while you are here.
Method one is to add a new field to the table;
The second method is to modify the name of the current database table, as a temporary table, create a database table to insert the data in the temporary table, so that the data can be upgraded.
Download Demo:
Click to open link
Android Sqlit Database upgrade, add fields