I have SQLite databases named database1
with a table t1
and database2
with a table t2
. I want to import table t2
from database2
into database1
. What command(s) should I use?
First, from the menu choose tool menu item. Second, choose the database and table that you want to import data then click the Next button. Third, choose CSV as the data source type, choose the CSV file in the Input file field, and choose the ,(comma) option as the Field separator as shown in the picture below.
Syntax. Following is the basic syntax of SQLite ATTACH DATABASE statement. ATTACH DATABASE 'DatabaseName' As 'Alias-Name'; The above command will also create a database in case the database is already not created, otherwise it will just attach database file name with logical database 'Alias-Name'.
The ". import" command is used to import CSV data into an SQLite table. The ". import" command takes two arguments which are the name of the disk file from which CSV data is to be read and the name of the SQLite table into which the CSV data is to be inserted.
Open database2
with the sqlite3
command-line tool and read the table definition with the command .schema t2
.
(Alternatively, use any other tool that allows to read the table definition.)
Then open database1
, attach the other database with the command:
ATTACH 'database2file' AS db2;
then create the table t2
, and copy the data over with:
INSERT INTO t2 SELECT * FROM db2.t2;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With