思路很简单,只需要把原来table中的数据转移就好
我们来看实现
@Override
private String createTableBook="create table Book(id integer primary key autoincrement,author text,price real,pages integer,name text)";
private String CREATE_TEMP_BOOK = "alter table Book rename to _temp_book";
private String INSERT_DATA = "insert into Book select * from _temp_book";
private String DROP_BOOK = "drop table _temp_book";
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(CREATE_TEMP_BOOK);//将原来的table重命名
db.execSQL