How to merge N SQLite database files into one if db has the primary field?

后端 未结 2 1788
广开言路
广开言路 2021-01-17 04:21

I have a bunch of SQLite db files, and I need to merge them into one big db files.

  • How can I do that?

Added

Based on this, I guess tho

2条回答
  •  清酒与你
    2021-01-17 04:44

    I'm just thinking off my head here... (and probably after everybody else has moved on, too).

    Mapping the primary key to "NULL" should yield the wanted result (no good if you use it as foreign key somewhere else, since the key probably exists, but has different contents)

    attach './abc2.db' as toMerge;
    insert into test select NULL, value, goody from toMerge.test;
    detach database toMerge;
    

    actual test:

    sqlite> insert into test select * from toMerge.test;
    Error: PRIMARY KEY must be unique
    sqlite> insert into test select NULL, value, goody from toMerge.test;
    sqlite> detach database toMerge;
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题