Fastest Way merge two SQLITE Databases

后端 未结 2 508
名媛妹妹
名媛妹妹 2021-02-02 14:48

I have 3 SQLite DBs, each having exactly the same set of 7 tables with respect to table structure. [They are Log Dumps from 3 different Machines].

I want to combine them

相关标签:
2条回答
  • 2021-02-02 15:07

    here is one way to merge two database with all tables of the same structure. I hope it could help.

    import sqlite3
    con3 = sqlite3.connect("combine.db")
    
    con3.execute("ATTACH 'results_a.db' as dba")
    
    con3.execute("BEGIN")
    for row in con3.execute("SELECT * FROM dba.sqlite_master WHERE type='table'"):
        combine = "INSERT INTO "+ row[1] + " SELECT * FROM dba." + row[1]
        print(combine)
        con3.execute(combine)
    con3.commit()
    con3.execute("detach database dba")
    
    0 讨论(0)
  • 2021-02-02 15:17

    Export each database to an SQL dump and then import the dumps into your new combined database.

    For GUIs have a look at http://www.sqlite.org/cvstrac/wiki?p=ManagementTools

    For example, with SQLiteStudio that will be Database > Export the database: Export format: SQL > Done.

    0 讨论(0)
提交回复
热议问题