如何连接来自不同数据库的表

如何连接来自不同数据库的表

本文介绍了SQLite - 如何连接来自不同数据库的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个使用SQLite数据库的应用程序,一切都按照它应该的方式工作。我现在正在添加需要第二个SQLite数据库的新功能,但我很难找到如何从不同的数据库连接表。 编辑:请参阅这个问题一个例子你可以适应你的语言,当你附加数据库如上所述 您可以使用将附加的另一个数据库文件附加到当前连接。 /sqlite.org/lang_attach.htmlrel =nofollow noreferrer> ATTACH 关键字。 attach'database1 .db'as db1; attach'database2.db'as db2; 您可以使用关键字查看所有连接的数据库 .databases 那么你应该能够 select * 从 db1.SomeTable a inner join db2.SomeTable b on b.SomeColumn = a.SomeColumn; 请注意,数据库名称 main 和 temp 保留用于主数据库和数据库保存临时表和其他临时数据对象。这两个数据库名称对每个数据库连接都存在,不应使用附件。 I have an application that uses a SQLite database and everything works the way it should. I'm now in the process of adding new functionalities that require a second SQLite database, but I'm having a hard time figuring out how to join tables from the different databases.If someone can help me out with this one, I'd really appreciate it!Edit: See this question for an example case you can adapt to your language when you attach databases as mentioned in the accepted answer. 解决方案 You can attach another database file to the current connection using the ATTACH keyword.attach 'database1.db' as db1;attach 'database2.db' as db2;You can see all connected databases with keyword.databasesThen you should be able to do the following.select *from db1.SomeTable a inner join db2.SomeTable b on b.SomeColumn = a.SomeColumn;Note that "[t]he database names main and temp are reserved for the primary database and database to hold temporary tables and other temporary data objects. Both of these database names exist for every database connection and should not be used for attachment". 这篇关于SQLite - 如何连接来自不同数据库的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-13 22:58