How do I import tables from another database in sqlite?

前端 未结 3 516
北海茫月
北海茫月 2021-02-02 14:47

I have SQLite databases named database1 with a table t1 and database2 with a table t2. I want to import table t2

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-02 15:06

    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;
    

提交回复
热议问题