Need an SQL query to connect the two tables in the different databases but the databases are in different server - sql-server-2005

Need an SQL query to connect the two tables that are in two different database,the databases are located in different servers.I am using SQL 2005.

You need (and should be googling) Linked Servers
http://technet.microsoft.com/en-us/library/ms188279.aspx

Related

SQL query with two different SQL istances

I would like to know how to make a select query in vb.net, with joins between tables contained in databases of two different instances of sql server.
thanks.

Compare two tables with different schema in SQL Server

I have two tables in different databases with different schema, how can I compare them both?
Let's say I have the DB1 with the table history.Table1 and another DB2 with the same table but in a different schema, backup.Table1.
Now I need to compare what's different besides the schema name obviously.
Try SQL Compare from Redgate. They allow you to compare pretty much everything from the actual data to the schema.
I dont believe there is any native functionality in sqlserver.
Compare SQL Server schemas and deploy differences fast
Compare and deploy SQL Server database contents

Query for multiple databases

Is there a way to write a single query so that if you are connected to database A it does one thing and if you are connected to database B it does another?
I am using SSMS 2008 to access SQL 2000 servers.
You can define views on database A and on database B with the same name and columns, but different construction. Then your query is just to select from the view.

is it possible to apply a query in hibernate which uses two databases?

I have two different databases (on same server) and i want to join tables across databases. I am using Hibernate, is it possible to create a query in hibernate which can join two tables in those databases?
Hibernate will create an SQL query for your HQL or Criteria query and this SQL will be sent through jdbc to the database. This means that hibernate does not support for what you are trying to do.
However, you can achieve the same result in some cases. Some databases give you the option to create an alias for a table that resides in a different database. So you will be able to write an SQL query that joins the two tables and execute it on the database.
We are doing that with DB2.
If you can do that, it depends on your database.
I guess, that it would impossible if you have two different databases (example DB2 and MySQL) but if both databases are of the same vendor, then maybe it's achievable.
You should try to find more info in you database server's documentation.

Query a Linked Server with Excel Connection

In the past, I have been querying various different databases (let's call them DB1, DB2, and DB3) by using Data->From Other Sources->From SQL Server in Excel. However, I want to be able to perform just one query (say, DBMaster) and using this to populate my data.
My thoughts: Use linked servers. I create DBMaster with linked servers to DB1, DB2, and DB3. However, I do not know how to access those individual databases from Excel. When I connect to DBMaster, I only get the tables on that database, not the tables on the linked servers. Does anyone know how I can do this?
Thank you!
You just need to connect your master database and exceute your query from there.
Just remember to put the server name before database name in your sql in FROM clause like :
[SERVER].[DATABASE].DBO.[TABLE_NAME]