0

Hi I have a requirement to join two table which are in two different databases. I found the following link to make use of synonym to do the task.

https://msdn.microsoft.com/en-us/library/ms162582.aspx

But when I add the Synonym it is not recognized by C#/Visual studio. Please suggest me a solution.

Please tell me a way to join two tables which are in two different databases.

Hemanth
  • 177
  • 2
  • 11
  • You could try the convention like this : `[schema_name].[database_name].[table_name].[field_name]` – Dhrumil May 15 '15 at 11:15
  • refer to this question http://stackoverflow.com/questions/5145637/querying-data-by-joining-two-tables-in-two-database-on-different-servers – saurabh64 May 15 '15 at 11:15
  • 2
    Which DBMS you use? Not all support cross-database queries. – MakePeaceGreatAgain May 15 '15 at 11:16
  • in my opinion joins should be done in database, so is it possible for you to create a view in your database which joins the two tables and reference this view in your c# code? – CeOnSql May 15 '15 at 11:16
  • Asking for solutions is not what SO is about. You need to come here with a specific problem - preferably with code you've written - and we can help you with the problem. Please don't ask us to provide solutions. – Enigmativity May 15 '15 at 11:16
  • `from [myBD].[dbo].[nameTable] as myTableAlias` works for me in Sql Server – mggSoft May 15 '15 at 11:19
  • Can you show us your query? – mggSoft May 15 '15 at 11:19

1 Answers1

-1

Use aliases like this

select t1.name as t1_name, t2.name as t2_name
from db1.your_table t1
join db2.your_table t2 on t1.id = t2.id
juergen d
  • 201,996
  • 37
  • 293
  • 362