简体   繁体   English

我可以在具有相同实例的 SQL Server 上使用链接服务器到 SQL Server 吗?

[英]Can I use linkserver to SQL Server on SQL Server with the same instance?

I would like to know what is the best way for use linkserver.我想知道使用链接服务器的最佳方式是什么。

I have a database in SQL Server called Sales and another database called Menus .我在 SQL Server 中有一个名为Sales数据库和另一个名为Menus数据库。 Both are on the same instance of JOSEPH-PC .两者都在JOSEPH-PC的同一个实例上。

My question: is it necessary to use linked server for it?我的问题:是否有必要为此使用链接服务器?

Or can I simply write a query like this:或者我可以简单地写一个这样的查询:

select * 
from Sales.dbo.table1 a 
inner join Menus.dbo.accces b on a.code = b.code

How could I store data in 2 tables from different databases for example a master-detail from my app in C#?如何将数据存储在来自不同数据库的 2 个表中,例如我的应用程序中的主从 C#?

Please let me know how I can make this.请让我知道我怎样才能做到这一点。

i dont think you can create the linked server for same sql server instance.我不认为您可以为同一个 sql server 实例创建链接服务器。 that has to be different instance or different server.那必须是不同的实例或不同的服务器。

if its about the best way to access the different database in same server same instance??如果它是访问同一服务器同一实例中不同数据库的最佳方式? the synonyms is here for that purpose.同义词就是为了这个目的。

create the synonyms for access from Menus in sales then you can use the synonym like local table on sales database.创建用于从sales Menus access的同义词,然后您可以使用synonymsales数据库上的本地表。

in sales database run the following command to create the synonyms for access so now in sales you can use menus_access as table, which will refer the access inside the menus databasesales数据库中运行以下命令来创建访问的同义词,所以现在在销售中,您可以使用menus_access作为表,这将引用菜单数据库中的访问

CREATE SYNONYM menus_access 
FOR Menus.dbo.access;

now in sales you can access the table as现在在销售中,您可以访问该表

 select * from menus_access

You will need to create view on one of the two databases and make sure your connection string points to that database.您需要在两个数据库之一上创建视图,并确保您的连接字符串指向该数据库。 You can create a view within SQL Server that connects to both databases like Create view across multiple databases您可以在连接到两个数据库的 SQL Server 中创建一个视图,例如跨多个数据库创建视图

You might also like to view how to retrieve data from two different database using join in SQL Server 2005 the way you have tried to do it.您可能还想查看如何使用 SQL Server 2005 中连接从两个不同的数据库中检索数据,就像您尝试过的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM