SQL joins a query between two different database files

I am creating a Windows application that has two SQL Server databases. One of them is on the path to the application / launch, and the other is on the other drive.

I have two SQL Server database files with different names. Both are in a different place. Both databases have identical tables. I want to create a connection request between tables for different databases.

Is it possible or not? If so, how? This is my first question in thread over thread, so please help me.

+4
source share
2 answers

If your databases are on the same sql server instances, there is no need to create linked servers (because it will hurt performance), you can just refer to the table with [DBName]. [Schema]. [TableName]. If you have the same database with 2 files, sql will handle this for you. If you have 2 instances, you can create linked servers or process them in applicaiont (combine 2 result sets)

+7
source

As far as I know, you cannot directly access the MDF file using VB.NET. This must be a SQL Server installation importing this MDF file. It will also be tricky, since you really cannot just specify SQL in the MDF file.

http://www.daniweb.com/software-development/vbnet/threads/115645/connecting-to-an-.mdf-database

Other people say you can do this. I recommend getting the free version of SQL Server 2008 Express. http://www.microsoft.com/en-us/download/details.aspx?id=23650

If you set up 2 servers with a linked server, all you have to do is

SELECT * FROM TableName t JOIN LinkedServerName.DatabaseName.dbo.TableName on ... 
+1
source

Source: https://habr.com/ru/post/1488817/


All Articles