Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I connect to an external database from a sql statement or a stored procedure?

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

something like:

SELECT a.UserID, b.DataIWantToGet 
  FROM mydb.Users as a, externaldb.Data as b
like image 776
Matt Avatar asked Dec 21 '09 19:12

Matt


People also ask

Can a stored procedure access another database?

You can work around this in SQL Server by creating a stored procedure that accesses data in another database and signing the procedure with a certificate that exists in both databases. This gives users access to the database resources used by the procedure without granting them database access or permissions.

How do you connect to a database in SQL?

On the Tools menu, click Data Connections. In the Data Connections dialog box, click Add. In the Data Connection Wizard, click Create a new connection to, click Receive data, and then click Next. On the next page of the wizard, click Database (Microsoft SQL Server or Microsoft Office Access only), and then click Next.


1 Answers

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

like image 63
OMG Ponies Avatar answered Sep 23 '22 14:09

OMG Ponies