magarwal
magarwal

Reputation: 574

Combining several sqlite databases (one table per file) into one big sqlite database

How to combine several sqlite databases (one table per file) into one big sqlite database containing all the tables. e.g. you have database files: db1.dat, db2.dat, db3.dat.... and you want to create one file dbNew.dat which contains tables from all the db1, db2...

Upvotes: 0

Views: 727

Answers (1)

magarwal
magarwal

Reputation: 574

Several similar questions have been asked on various forums. I posted this question (with answer) for a particular reason. When you are dealing with several tables and have indexed many fields there. It causes unnecessary confusion to create index properly into the destination database tables. You may miss 1-2 index and its just annoying. The given method can also deal with large amount of data i.e. when you really have gbs of tables. Following are the steps to do so:

  1. Download sqlite expert: http://www.sqliteexpert.com/download.html
  2. Create a new database dbNew: File-> New Database
  3. Load the 1st sqlite database db1 (containing a single table): File-> Open Database
  4. Click on the 'DDL' option. It gives you a list of commands which are needed to create the particular sqlite table CONTENT.
  5. Copy these commands and select 'SQL' option. Paste the commands there. Change the name of destination table DEST (from default name CONTENT) into whatever you want. 6'Click on 'Execute SQL'. This should give you a copy of the table CONTENT in db1 with the name DEST. The main utility of doing it is that you create all the index also in the DEST table as they were in the CONTENT table.
  6. Now just click and drag the DEST table from the database db1 to the database dbNew.
  7. Now just delete the database db1.
  8. Go back to step 3 and repeat with the another database db2 etc.

Upvotes: -1

Related Questions