469,148 Members | 1,271 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,148 developers. It's quick & easy.

Temp Table on Linked Server

Trying to do this all day and googling for answers but found none, hope
someone can help. Thanks in advance.

select * into
OPENROWSET('SQLOLEDB','SERVER';'uid';'pwd',##test)
from LocalTable

Reason: I am joining local tables with linked server tables using the
format "LinkedServer.database.owner.object" to execute a query, it
takes forever to execute since the tables joined on the remote servers
have more than 50Mil records. I read somewhere that sql server needs to
copy the tables locally to the temp db and does the join there, hence I
was hoping to dump the data of the local database into a temp table on
the remote server and then do a join with OPENQUERY, which will execute
the query on the linked server and return the results.

Oct 7 '05 #1
8 12177
If the table is smaller on the local server then why not create a sp on the
remote one that joins these two tables and call the sp remotely?

--
Andrew J. Kelly SQL MVP
"Ootyguy" <np*****@hotmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Trying to do this all day and googling for answers but found none, hope
someone can help. Thanks in advance.

select * into
OPENROWSET('SQLOLEDB','SERVER';'uid';'pwd',##test)
from LocalTable

Reason: I am joining local tables with linked server tables using the
format "LinkedServer.database.owner.object" to execute a query, it
takes forever to execute since the tables joined on the remote servers
have more than 50Mil records. I read somewhere that sql server needs to
copy the tables locally to the temp db and does the join there, hence I
was hoping to dump the data of the local database into a temp table on
the remote server and then do a join with OPENQUERY, which will execute
the query on the linked server and return the results.

Oct 7 '05 #2

Ootyguy napisal(a):
Trying to do this all day and googling for answers but found none, hope
someone can help. Thanks in advance.

select * into
OPENROWSET('SQLOLEDB','SERVER';'uid';'pwd',##test)
from LocalTable

Reason: I am joining local tables with linked server tables using the
format "LinkedServer.database.owner.object" to execute a query, it
takes forever to execute since the tables joined on the remote servers
have more than 50Mil records. I read somewhere that sql server needs to
copy the tables locally to the temp db and does the join there, hence I
was hoping to dump the data of the local database into a temp table on
the remote server and then do a join with OPENQUERY, which will execute
the query on the linked server and return the results.

Using OPENROWSET for big tabels is not good idea, so you have right
trying copy this table.
To copy this tabel you can use for example DTS. It will take you couple
minutes and you'll have what you want.

Oct 7 '05 #3
Andrew thank you for your idea. But the problem that I can't do this is
because, I have to join with more than 15 remote servers (in different
states, all having the same database) and I do not have permission or
control over them, all I have is the datareader role. Also in this case
as new states (databases) are added I will have to ask the dba of the
other state to create this sp for me which they may not agree.

Oct 8 '05 #4
Roan, thanks. I will try this when I get back to work on Monday.

Oct 8 '05 #5
Ootyguy (np*****@hotmail.com) writes:
Trying to do this all day and googling for answers but found none, hope
someone can help. Thanks in advance.

select * into
OPENROWSET('SQLOLEDB','SERVER';'uid';'pwd',##test)
from LocalTable

Reason: I am joining local tables with linked server tables using the
format "LinkedServer.database.owner.object" to execute a query, it
takes forever to execute since the tables joined on the remote servers
have more than 50Mil records. I read somewhere that sql server needs to
copy the tables locally to the temp db and does the join there, hence I
was hoping to dump the data of the local database into a temp table on
the remote server and then do a join with OPENQUERY, which will execute
the query on the linked server and return the results.


It may copy the entire table over the wire - but not by necssity.

What you try above is a dead end. What you could consider is to
optimize by hand, so to speak. If you know that you only will retrieve
a handful of those remote rows, then get those rows into a local table,
and use OPENQUERY, to be sure that it is a pass-through query.

Having 15 tables from 15 servers in the same query sounds like a nightmare
to me. Maybe you should consider replication to get the data into one
spot.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Oct 9 '05 #6
Let me clarify that I am not joining 15 tables against 15 remote
servers in one query, it is more like 6 linked tables and 2 local
tables against each database that is linked and this same query is
repeated against all the remote linked servers to gather data, create a
text file and ftp the file to a different location.

Since this is a job, it doesn't matter if it takes upto 45mins or an
hour, the problem is it works ok when the tables joined on the linked
servers are small, as more databases are added and the tables are large
it takes forever to execute.

Oct 10 '05 #7
I am not sure if I can use DTS because my current logic generates
dynamic sql for each remote server (around 15 servers, which will grow,
and information -uid;pwd;server; is stored in a table), the existing
DTS calls a stored procedure that generates this dynamic sql, executes
against each server, dumps the data in a temp table and then uses bcp
to generate a file, the DTS continues and ftp's the data to a different
location.

Oct 10 '05 #8
Ootyguy (np*****@hotmail.com) writes:
Let me clarify that I am not joining 15 tables against 15 remote
servers in one query, it is more like 6 linked tables and 2 local
tables against each database that is linked and this same query is
repeated against all the remote linked servers to gather data, create a
text file and ftp the file to a different location.

Since this is a job, it doesn't matter if it takes upto 45mins or an
hour, the problem is it works ok when the tables joined on the linked
servers are small, as more databases are added and the tables are large
it takes forever to execute.


If you join the six remote tables alone, how much data you get? Could
you run that query through OPENQUERY? Or would that still be too much
data to bring over?

Hm, in your OPENQUERY you could actually join to your local tables, that
is:

SELECT * FROM
OPENQUERY(REMOTE, 'SELECT ...
FROM localtable ..
JOIN YOURSERVER.db.dbo.tbl ')

Of course, you need to convince the other DBAs to set up linked servers
to your servers. But if they are not willing to co-operate, you should
probably not pull this data at all. Or you should talk with a manager.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Oct 10 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Per | last post: by
4 posts views Thread by Neil Ginsberg | last post: by
7 posts views Thread by John Baker | last post: by
4 posts views Thread by Wayne Wengert | last post: by
1 post views Thread by imani_technology_spam | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.