I have SQLite databases named database1
with a table t1
and database2
with a table t2
. I want to import table t2
You could use the sqlite3 .dump
command to pipe the dump output into the other db. It takes an optional argument with the table name.
db1=~/mydb1.sqlite
db2=~/mydb2.sqlite
t=t2
sqlite3 "$db2" ".dump $t" | sqlite3 "$db1"
If you have no common tables in both databases, you can leave out the table name and copy all tables.
If the tables are big, this may be slow because it will do INSERTs. If they are huge, and it is really too slow, maybe .import
would be faster. You could try something like
sqlite3 "$db2" ".schema $t" | sqlite3 "$db1"
sqlite3 "$db2" "SELECT * FROM $t" | sqlite3 "$db1" ".import /dev/stdin $t"