Serving the Quantitative Finance Community

 
User avatar
yuanche17
Topic Author
Posts: 0
Joined: August 8th, 2003, 3:34 am

join tables from two db servers in sql server 2000

December 10th, 2003, 5:40 pm

Does anyone know if sql server 2000 allows a single query to inn-join tables which reside on two different database servers (not different databases, or tables, i.e. each has a unique server name and a workstation name) ?
 
User avatar
csparker
Posts: 0
Joined: October 3rd, 2001, 7:53 am

join tables from two db servers in sql server 2000

December 11th, 2003, 9:09 am

If it doesn't them sql server isn't too smart. Don't expect the query to perform too well though. Any distributed query that requires a join will be slow as the machine driving the query is likely to know nothing of the remote database, so will only be able to use a sort/merge join rather than a more optimal one. Depending on what you want to do, you could consider replication of tables between the databases (not sure if SQL Server does this) or simply copying the data you need from the remote database into an indexed table on the local machine. Hope this helps.
 
User avatar
Silvershark
Posts: 0
Joined: November 10th, 2002, 2:27 pm

join tables from two db servers in sql server 2000

December 11th, 2003, 10:30 am

QuoteOriginally posted by: yuanche17Does anyone know if sql server 2000 allows a single query to inn-join tables which reside on two different database servers (not different databases, or tables, i.e. each has a unique server name and a workstation name) ?The preferred way is to use Replication, ie set up Publish/Subscribe relationship between databases.This way you can access tables in the remote database as they where tables on the local. SQLServer handles the rest.
 
User avatar
DominicConnor
Posts: 41
Joined: July 14th, 2002, 3:00 am

join tables from two db servers in sql server 2000

December 12th, 2003, 8:52 am

Mr Parker is quite right that replication is often the right way.However, you can write multi server queries in MS TSQL. using the OPENROWSET keyword.In essence you're using OLEDB to return rows, which Select can then join to your data. The documentation on this is quite adequate, but feel free to ask questions if you get stuck.The problem you may hit is that you are going to create locks on both databases whilst executing a query that by necessity runs quite slowly. This may mean that your code runs at an acceptable speed, but other users experience significant delays. Be aware that you many need SP3 for this to run correctly.
 
User avatar
Silvershark
Posts: 0
Joined: November 10th, 2002, 2:27 pm

join tables from two db servers in sql server 2000

December 12th, 2003, 1:10 pm

The great thing with the techniques is that you don't even need to rely on a SQL Server, it could be any db with OLE DB support. Watch out for locking, but that's a resposibility that comes with any system development of course.
 
User avatar
asd
Posts: 17
Joined: August 15th, 2002, 9:50 pm

join tables from two db servers in sql server 2000

December 16th, 2003, 5:37 am

In Oracle, it is quite easy to do this - Create a DB Link from one database to another. This can be done with SQL navigator or any GUI like TOAD,etc. Then use the tablename + DB link name within the query.eg.,There are 2 database - DB1 and DB2.Create a DBLINK on DB1, for connecting to DB2. Name this mydb_DB2.Then on DB1, run a query likeselect * from table1, table2@mydb_DB2where......I don't know the equivalent in SQL server, but I guess there could be similar thing with a different name.Hope it helps.Good luck!
Last edited by asd on December 15th, 2003, 11:00 pm, edited 1 time in total.
 
User avatar
Yurtle
Posts: 0
Joined: March 29th, 2003, 4:55 am

join tables from two db servers in sql server 2000

December 16th, 2003, 9:11 am

you can creat a DB link in SQL server as well.