java SQLite:将表从一个数据库复制到另一个数据库的最简单方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29220677/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 14:53:05  来源:igfitidea点击:

SQLite: Easiest way to copy a table from one database to another?

javasqlite

提问by user6189

I have two sqlite databases and want to copy a table from database A to database B. The other tables in database A should not be copied. What is the easiest way to do that in Java?

我有两个 sqlite 数据库,想从数据库 A 复制一个表到数据库 B。数据库 A 中的其他表不应该被复制。在 Java 中最简单的方法是什么?

I could definitively do something like Select * from A and then insert all of this into database B, but shouldn't there a better way?

我可以明确地做一些类似 Select * from A 的事情,然后将所有这些插入到数据库 B 中,但不应该有更好的方法吗?

回答by Colonel Thirty Two

Open the database you are copying from, then run this code to attach the database you are copying to and then copy a table over.

打开要从中复制的数据库,然后运行此代码以附加要复制到的数据库,然后复制一个表。

ATTACH DATABASE 'other.db' AS other;

INSERT INTO other.tbl
SELECT * FROM main.tbl;