Solved

OPENQUERY vs. OPENROWSET

Posted on 2007-04-09
3
3,421 Views
Last Modified: 2012-06-21
Can someone explain to me what do OPENQUERY and OPENROWSET do, how and when are they used and what is the difference between the two. Please do not provide links to articles, I tried reading different articles but still cannot completely understand those two
0
Comment
Question by:YZlat
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 18876951
syntax:

OPENQUERY ( linked_server ,'query' )

OPENROWSET
( { 'provider_name' , { 'datasource' ; 'user_id' ; 'password'
   | 'provider_string' }
      , {   [ catalog. ] [ schema. ] object
       | 'query'
     }
   | BULK 'data_file' ,
       { FORMATFILE = 'format_file_path' [ <bulk_options> ]
       | SINGLE_BLOB | SINGLE_CLOB | SINGLE_NCLOB }
} )

so, openquery uses a predefined linked server, while openrowset has to sepcify all the connection options.

for the rest, it's the same

0
 
LVL 35

Author Comment

by:YZlat
ID: 18877038
thanks Angel!
0
 

Expert Comment

by:hpsuser
ID: 23006165
One quick comment:  In limited experience using both, I have found that OpenRowSet can perform better (some queries that bomb out using OpenQuery after a while because of resource issues run using OpenRowSet)....I haven't done enough testing to know for sure that this is the cause was OPENQUERY vs. OPENROWSET, but FWIW I always use OpenRowSet when possible.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question