<small id='MEx6g'></small><noframes id='MEx6g'>

  1. <i id='MEx6g'><tr id='MEx6g'><dt id='MEx6g'><q id='MEx6g'><span id='MEx6g'><b id='MEx6g'><form id='MEx6g'><ins id='MEx6g'></ins><ul id='MEx6g'></ul><sub id='MEx6g'></sub></form><legend id='MEx6g'></legend><bdo id='MEx6g'><pre id='MEx6g'><center id='MEx6g'></center></pre></bdo></b><th id='MEx6g'></th></span></q></dt></tr></i><div id='MEx6g'><tfoot id='MEx6g'></tfoot><dl id='MEx6g'><fieldset id='MEx6g'></fieldset></dl></div>

    <tfoot id='MEx6g'></tfoot>
  2. <legend id='MEx6g'><style id='MEx6g'><dir id='MEx6g'><q id='MEx6g'></q></dir></style></legend>

      • <bdo id='MEx6g'></bdo><ul id='MEx6g'></ul>

      通过连接不同服务器上两个数据库中的两个表来查询数据

      Querying data by joining two tables in two database on different servers(通过连接不同服务器上两个数据库中的两个表来查询数据)

          <bdo id='5neok'></bdo><ul id='5neok'></ul>
            <tbody id='5neok'></tbody>
          <legend id='5neok'><style id='5neok'><dir id='5neok'><q id='5neok'></q></dir></style></legend>
        • <i id='5neok'><tr id='5neok'><dt id='5neok'><q id='5neok'><span id='5neok'><b id='5neok'><form id='5neok'><ins id='5neok'></ins><ul id='5neok'></ul><sub id='5neok'></sub></form><legend id='5neok'></legend><bdo id='5neok'><pre id='5neok'><center id='5neok'></center></pre></bdo></b><th id='5neok'></th></span></q></dt></tr></i><div id='5neok'><tfoot id='5neok'></tfoot><dl id='5neok'><fieldset id='5neok'></fieldset></dl></div>

              1. <tfoot id='5neok'></tfoot>

                <small id='5neok'></small><noframes id='5neok'>

                本文介绍了通过连接不同服务器上两个数据库中的两个表来查询数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在不同服务器上的两个不同数据库中有两个表,我需要加入它们以进行少量查询.我有哪些选择?我该怎么办?

                There are two tables in two different databases on different servers, I need to join them so as to make few queries. What options do I have? What should I do?

                推荐答案

                您需要使用 sp_addlinkedserver 来创建服务器链接.有关用法,请参阅参考文档.建立服务器链接后,您将像往常一样构造查询,只需在数据库名称前加上另一台服务器即可.即:

                You'll need to use sp_addlinkedserver to create a server link. See the reference documentation for usage. Once the server link is established, you'll construct the query as normal, just prefixing the database name with the other server. I.E:

                -- FROM DB1
                SELECT *
                FROM [MyDatabaseOnDB1].[dbo].[MyTable] tab1
                    INNER JOIN [DB2].[MyDatabaseOnDB2].[dbo].[MyOtherTable] tab2
                        ON tab1.ID = tab2.ID
                

                一旦建立了链接,您还可以使用OPENQUERY 在远程服务器上执行 SQL 语句并只将数据传回给您.这可能会快一点,它会让远程服务器优化您的查询.如果您在上面的示例中将数据缓存在 DB1 上的临时(或内存中)表中,那么您将能够像连接标准表一样查询它.例如:

                Once the link is established, you can also use OPENQUERY to execute a SQL statement on the remote server and transfer only the data back to you. This can be a bit faster, and it will let the remote server optimize your query. If you cache the data in a temporary (or in-memory) table on DB1 in the example above, then you'll be able to query it just like joining a standard table. For example:

                -- Fetch data from the other database server
                SELECT *
                INTO #myTempTable
                FROM OPENQUERY([DB2], 'SELECT * FROM [MyDatabaseOnDB2].[dbo].[MyOtherTable]')
                
                -- Now I can join my temp table to see the data
                SELECT * FROM [MyDatabaseOnDB1].[dbo].[MyTable] tab1
                    INNER JOIN #myTempTable tab2 ON tab1.ID = tab2.ID
                

                查看关于 OPENQUERY 的文档 以查看更多示例.上面的例子非常做作.在这个特定示例中,我肯定会使用第一种方法,但是如果您使用查询过滤掉一些数据,使用 OPENQUERY 的第二个选项可以节省一些时间和性能.

                Check out the documentation for OPENQUERY to see some more examples. The example above is pretty contrived. I would definitely use the first method in this specific example, but the second option using OPENQUERY can save some time and performance if you use the query to filter out some data.

                这篇关于通过连接不同服务器上两个数据库中的两个表来查询数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                SQL query to group by day(按天分组的 SQL 查询)
                What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                Include missing months in Group By query(在 Group By 查询中包含缺失的月份)

                <legend id='7fGmP'><style id='7fGmP'><dir id='7fGmP'><q id='7fGmP'></q></dir></style></legend>
              2. <tfoot id='7fGmP'></tfoot>
                  <tbody id='7fGmP'></tbody>
                      • <bdo id='7fGmP'></bdo><ul id='7fGmP'></ul>

                      • <i id='7fGmP'><tr id='7fGmP'><dt id='7fGmP'><q id='7fGmP'><span id='7fGmP'><b id='7fGmP'><form id='7fGmP'><ins id='7fGmP'></ins><ul id='7fGmP'></ul><sub id='7fGmP'></sub></form><legend id='7fGmP'></legend><bdo id='7fGmP'><pre id='7fGmP'><center id='7fGmP'></center></pre></bdo></b><th id='7fGmP'></th></span></q></dt></tr></i><div id='7fGmP'><tfoot id='7fGmP'></tfoot><dl id='7fGmP'><fieldset id='7fGmP'></fieldset></dl></div>

                          <small id='7fGmP'></small><noframes id='7fGmP'>