Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

How to join a local table to a remote table by way of a linked server Expand / Collapse
Author
Message
Posted Sunday, February 26, 2012 9:47 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, September 12, 2014 1:36 PM
Points: 128, Visits: 916
Comments posted to this topic are about the item How to join a local table to a remote table by way of a linked server
Post #1257999
Posted Sunday, February 26, 2012 10:09 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, April 10, 2013 4:23 AM
Points: 18, Visits: 56
Thanks for the details. I am using linked server for accessing data from remote servers. But I wonder whether I need to handle the transactions manually, if I use linked servers for writing data.!! what you think ?
Post #1258007
Posted Sunday, February 26, 2012 11:21 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, September 12, 2014 2:30 AM
Points: 1,422, Visits: 1,838
You may be interested in reading one of my posts, which explores the use of EXECUTE...AT clause for executing queries against linked servers: http://beyondrelational.com/blogs/nakul/archive/2011/01/10/executing-queries-against-linked-servers.aspx

Thanks & Regards,
Nakul Vachhrajani.
http://nakulvachhrajani.com
Be courteous. Drive responsibly.

Follow me on
Twitter: @sqltwins
Google Plus: +Nakul
Post #1258027
Posted Monday, February 27, 2012 12:39 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, May 27, 2014 3:18 AM
Points: 105, Visits: 133
Hi, any specific reason way you don't use the openquery command?
Post #1258041
Posted Monday, February 27, 2012 1:34 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, September 12, 2014 2:30 AM
Points: 1,422, Visits: 1,838
I believe the reason would be because OPEN queries require that Adhoc queries be enabled on the SQL Server, which, depending upon the environment and the situation, might be considered a security loop-hole.

Thanks & Regards,
Nakul Vachhrajani.
http://nakulvachhrajani.com
Be courteous. Drive responsibly.

Follow me on
Twitter: @sqltwins
Google Plus: +Nakul
Post #1258063
Posted Monday, February 27, 2012 3:16 AM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, September 18, 2014 7:18 AM
Points: 58, Visits: 214
Linked serverd id quite a big subject with the security levels, ditributed transactions etc.and I think this post could have gone in to a little more detail without detracting from the subject matter.

I think Openquery was worth mentioning and I dont think it was avoided on account of security as the way this linked server example has been set up is highly inssecure anyway.

2 interesting points I think are worth making though.

As a general rule, don't do linked security in the way noted in the article as all connections will be executed remotely with this remote user regardless of the loacal user. Better to map all allowed local users to a remote login and best to use windows security locally if possible.

Secondly there isa gothcha thats worth noting. The linked server with inner join will not work woth XML columns. You would have to use openquery and convert the remote xml field to varchar and then convert it back again.

And finally I would like to mention that, touched on in the article, the copying of a remote table to a local temp table can often be a good idea as this avoids the need for a distributed transaction and therefore reduces overhead and complexity of the security system.

Otherwise I thought the article was a pretty good introduction.

Dave




David Bridge
David Bridge Technology Limited
www.davidbridgetechnology.com
Post #1258104
Posted Monday, February 27, 2012 7:10 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, April 1, 2014 9:27 AM
Points: 1, Visits: 50
Copying the entire remote table into a local temp table is not an option when the remote table has millions of rows. Have a look at the REMOTE join hint. There are a couple of caveats with this hint, but if one can properly index the remote table, using this join hint provides very good performance.
Post #1258225
Posted Monday, February 27, 2012 7:36 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 10:28 AM
Points: 1,660, Visits: 4,750
I agree that it's best to map local logins to an account on the remote server, rather than have all logins access the linked server using a default security context. Otherwise, even an account with nothing but PUBLIC access will have equal access to the linked server.

Mapping local logins to remote accounts can be done even when the remote server doesn't have (or doesn't support) windows authentication. Here is how one my linked servers are configured where the remote server is Oracle. A windows domain account, MYCORP\ReportingUser, can access the linked server under the context of the remote Oracle account, RPT_USER.

Local server login to remote server login mappings:

Local Login: MYCORP\ReportingUser
Impersonate: No
Remote User: RPT_USER (account on remote Oracle server)
Remote Password: ########

For a login not defined in the above list, connections will:
- Not be made
Post #1258244
Posted Monday, February 27, 2012 8:19 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, August 21, 2014 5:31 PM
Points: 33, Visits: 413
When I require live data, I almost always join against OPENQUERY resultsets - much, much, MUCH faster than directly joining to the remote server.

Or else an SSIS job.

-sff
Post #1258279
Posted Monday, February 27, 2012 8:53 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, June 21, 2012 9:03 AM
Points: 5, Visits: 29
Nice article. I find in actual use where the person creating the linked server is a company level DBA that providing scripts is a necessary component. Also be aware that you may need to add multiple users (we did). There is also some detail in regards to linking to non-SQL Server servers (Oracle?) that would be useful to see.

Joshua
Post #1258317
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse