How OPENROWSET and OPENDATASOURCE function is used to access external data

Describe how OPENROWSET and OPENDATASOURCE function is used to access external data.

OPENROWSET: Includes all connection information that is required to access remote data from an OLE DB data source. It can be references from a FROM clause and is used to access the tables on a linked server. It can also be referenced as a target table of INSERT, DELETE, and UPDATE statements.

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

Example
SELECT * FROM OPENROWSET('SQLNCLI',Server=Brighton1;Trusted_Connection=yes;', 'SELECT sal, employee_name FROM Company.employee.ID')

OPENDATASOURCE: Provides ad hoc connection information without a linked server name.

Syntax:
OPENDATASOURCE ( provider_name, init_string )

Example: The example cretes a ad hoc connection to the payroll instance of a SQL server in US. It queries the Company.HumanResources.Employee table.
SELECT * FROM OPENDATASOURCE('SQLNCLI', 'Data Source=US\Payroll;Integrated Security=SSPI') . Company.HumanResources.Employee
What is “Index Tuning Wizard”?
Index Tuning Wizard is a software application that identifies tables which have inefficient indexes.......
Partitioning an important part of database optimization
Partitioning distributes database tables over different database which may reside on a different server.........
SSIS Interview Questions and Answers - Freshers & Experienced
SSIS interview questions and answers for freshers and experienced - Difference between control flow and data flow?, If you want to send some data from Access database to SQL server database. What are different component of SSIS will you use?, Explain why variables called the most powerful component of SSIS?
Post your comment