Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create additional table in existing SQLITE (without data loss)

I would like to add an additional table in my existing DB without loss of the data. So dropping the tables and create them new is no option. What is the best way to do that?

like image 681
venni Avatar asked Jul 05 '12 20:07

venni


People also ask

How many tables can I create in SQLite?

As many as you want, within the limits of available disk space. in one Database how many tables can i create? A billion or so, though you will run out of disk space first.

How many writes per second SQLite?

Actually, SQLite will easily do 50,000 or more INSERT statements per second on an average desktop computer. But it will only do a few dozen transactions per second.

Can you modify any table in any way or are there limits SQLite?

SQLite supports a limited subset of ALTER TABLE. The ALTER TABLE command in SQLite allows these alterations of an existing table: it can be renamed; a column can be renamed; a column can be added to it; or a column can be dropped from it.


2 Answers

It seems to be much easier. I use the SQLiteOpenHelper. So the onCreate() is never been called if the DB already exists. When the version number increases, onUpdate() is called. In onUpdate() I have added my new table with "create table if not exists". From the documentation of SQLITE.ORG: However, if the "IF NOT EXISTS" clause is specified as part of the CREATE TABLE statement and a table or view of the same name already exists, the CREATE TABLE command simply has no effect (and no error message is returned). Now the table is created and its fine.

like image 76
venni Avatar answered Oct 01 '22 15:10

venni


the way I have done it is create a seperate database, copy everything from the current one over to the temp new one then drop the old database do whatever there and then copy the information back from the temp database.

not sure if there is another way to do it but if there is I would love to hear about it

like image 35
tyczj Avatar answered Oct 01 '22 15:10

tyczj