0

I have a zip file containing several .db files (~ 30 files). Each of these .db files correspond to a table, e.g., the "fuel_transaction.db" file contains a "fuel_transaction" table, "payment_transaction.db" contains "payment_transaction" table and so on.

I am very new to SQLite and whatever I've found is about importing CSV or sql files.. I was wondering if there is any way to import all these tables, i.e., all .db files (all at once) into a database in SQLite? Should I first create an empty database in sqlite and then import each file separately into this new database?

Thanks,

1

For each database file (other.db) that must export tables to main.db:

sqlite3 other.db .dump | sqlite3 main.db

Or if you want to check the generated commands:

sqlite3 other.db .dump > log
sqlite3 main.db < log

Another method: (not so good as it does not import the primary key and column types)

First open the main database:

sqlite3 main.db

Then for each database containing tables to be imported:

ATTACH DATABASE 'other.db' AS other;
CREATE TABLE tablename AS SELECT * FROM other.tablename;
DETACH DATABASE other;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.