---
title: "How to communicate with two separate Database in MSSQL Server?"  
description: "How to communicate with two separate Database in MSSQL Server?"  
author: "Steilla Mitchel"  
published: 2023-07-30  
updated: 2023-07-31  
canonical: https://www.mindstick.com/forum/159375/how-to-communicate-with-two-separate-database-in-mssql-server  
category: "mssql server"  
tags: ["mssql server", "sql server", "sql"]  
reading_time: 2 minutes  

---

# How to communicate with two separate Database in MSSQL Server?

How to [communicate with two](https://www.mindstick.com/forum/159376/foreign-key-works-if-we-communicate-with-two-databases-in-mssql-server) separate [Databases](https://www.mindstick.com/startup/34/airbyte-the-open-source-platform-simplifying-data-integration-for-warehouses-lakes-and-databases) in MS [SQL Server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server)?

## Replies

### Reply by Aryan Kumar

There are a few ways to communicate with [two separate](https://answers.mindstick.com/qa/34817/who-was-the-only-president-to-serve-two-separate-terms-in-office) databases in [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database) [Server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over). Here are some of the most common methods:

- **Using linked servers:** Linked servers allow you to connect to a remote database as if it were a local database. This means that you can use the same SQL commands to access data in both databases.
- **Using distributed queries:** Distributed queries allow you to run a single query that spans multiple databases. This can be a convenient way to combine data from different databases.
- **Using stored procedures:** Stored procedures are a way to encapsulate a set of SQL commands in a single unit. This can be useful for communicating with two separate databases, as you can create a stored procedure that runs the necessary commands on both databases.

Which method you use will depend on your specific needs and the requirements of your application.

Here are some additional details about each method:

- **Linked servers:** To create a linked server, you will need to specify the name of the remote database, the server name, and the authentication method. Once you have created a linked server, you can use it to connect to the remote database and run SQL commands.
- **Distributed queries:** Distributed queries are a bit more complex than linked servers, but they can be more powerful. To run a distributed query, you will need to specify the names of the databases that you want to query, as well as the specific tables and columns that you want to access.
- **Stored procedures:** Stored procedures are a good option if you need to communicate with two separate databases in a consistent way. To create a stored procedure, you will need to specify the name of the stored procedure, the database that it will be stored in, and the SQL commands that it will contain. Once you have created a stored procedure, you can run it from any database that has access to the stored procedure.


---

Original Source: https://www.mindstick.com/forum/159375/how-to-communicate-with-two-separate-database-in-mssql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
