如何从sql语句或存储过程连接到外部数据库? [英] How can I connect to an external database from a sql statement or a stored procedure?

查看:145
本文介绍了如何从sql语句或存储过程连接到外部数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据库上运行SQL语句或存储过程时,您是否可以连接到外部数据库并从中提取数据?

When running a SQL statement or a stored procedure on a database, can you connect to an external database and pull data from there?

如下:

SELECT a.UserID, b.DataIWantToGet 
  FROM mydb.Users as a, externaldb.Data as b


推荐答案

您需要设置链接服务器实例。然后可以引用外部数据库,就像它是一个SQL Server数据库。

You'll need to setup a Linked Server instance. Then you can reference the external database as though it were a SQL Server database.

这篇关于如何从sql语句或存储过程连接到外部数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆