How to copy table fast from one database to another

随声附和 提交于 2019-12-01 08:28:57

问题


I have one database with one table and another database. I need to copy this one table from the first database (with simple table) to the second. (In second database it should be fts3 table). So, I can open both databases, create new fts3 in the second db and copy all data from the first to the second via select -> insert queries. But is there any other ways to do it faster and better?


回答1:


As far as I know the methodology you described (i.e. INSERT INTO db2.tbl SELECT * FROM db1.tbl) should generally be the most efficient.

What you can do is tweak sqlite to do it faster. The first thing that comes to mind is to disable journaling (normally dangerous, but should be acceptable in your scenario as you still have an original of the data):

pragma PRAGMA journal_mode=OFF:

You can also turn off the synchronous pragma (also dangerous):

PRAGMA synchronous=OFF;

There are one or two more pragmas you can play with that could make a difference, but I think the two I mention will have the biggest impact.

Be sure to restore those pragmas to their original values after the copy.




回答2:


Well yes, that is the best way. Create table and then insert the data:

INSERT INTO `toDB`.`tableName` SELECT * FROM `fromDB`.`tableName` 


来源:https://stackoverflow.com/questions/10371446/how-to-copy-table-fast-from-one-database-to-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!