vb.net 合并来自不同数据库的sqlite中的两个表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18712761/
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
Merging two tables in sqlite from different database
提问by Harsh
I need to merge two tables in sqlite based on a common column. The problem is both the tables belong to different databases. So, what would be an efficient way to merge the tables here?
我需要根据一个公共列合并 sqlite 中的两个表。问题是两个表都属于不同的数据库。那么,在这里合并表格的有效方法是什么?
A sample table would be like this with the desired result. But the problem is these two tables are in different databases.
示例表将是这样的,具有所需的结果。但问题是这两个表在不同的数据库中。
Table 1: Employee_Pro_Profile
Columns: Emp_Id, Emp_Name, Emp_Sal
Table 2: Employee_Personal_Profile
Columns: Emp_Id, Emp_Home_Address, Emp_Phone
Resulting Table: Employee_Complete
Columns: Emp_Id, Emp_Name, Emp_Sal, Emp_Home_Address, Emp_Phone
回答by MrSimpleMind
Okey first you have to attach the databases, to your current connection.
好的,首先您必须将数据库附加到您当前的连接。
SQLite give you this by using ATTACH.
SQLite 通过使用 ATTACH 为您提供此功能。
The ATTACH DATABASE statement adds another database file to the current database connection. ATTACH LINK
ATTACH DATABASE 语句将另一个数据库文件添加到当前数据库连接。 附加链接
Run this:
运行这个:
attach database DatabaseA.db as DbA;
attach database DatabaseB.db as DbB;
Now you can reference the databases as you do with tables...
现在您可以像处理表一样引用数据库...
select
*
from
DbA.Table1 A
inner join
DbB.Table2 B on B.Emp_Id = A.Emp_Id;
There is a limit to the number of databases that can be simultaneously attached to a single database connection.
可以同时连接到单个数据库连接的数据库数量是有限制的。
Check your settings if something goes wrong, the flag is:
如果出现问题,请检查您的设置,标志是:
#define SQLITE_LIMIT_ATTACHED 7 // SQLITE_LIMIT_ATTACHED - The maximum number of attached databases.
#define SQLITE_LIMIT_ATTACHED 7 // SQLITE_LIMIT_ATTACHED - The maximum number of attached databases.

