Вопрос

I have two different databases in SQL Server, lets say db1 and db2, and I need to join data between them, but using my application that has access only to db1.

So, I thought of two possibilities: the first one is to create a view in db 1 that reads data from db 2. The second one is to create some kind of logical or virtual database, kind of db3, so I can access db1 and db2 through db3. Is it possible?

Opened for other suggestions.

Это было полезно?

Решение

The view is a good option, I don't see the need for a "virtual" db. Use the KISS principle.

Другие советы

"logical or virtual database"? no need. Assuming the DBs are on the same server, a view or even a direct select like select * from db2.dbo.table would do the trick

If they are not, you would need to create a linked server on DB1 pointing to DB2

Yes, create a stored procedure and do a "union/join" SQL query.

In the SQL Query in the "from" clause you need to write the "from [DatabaseName].[Schema].[Table]"

You need to host the stored procedure in the database where your application has access to.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top