Query SQL statements across servers sample

Source: Internet
Author: User

If 2 databases are on the same machine:
INSERT INTO database_a. Table1 (col1,col2,col3----)
Select col11,col22,col33--from Database_b. Table11
If not on the same machine, it is the content of this article:

-----------------------------------------------------------------------------------------

Query SQL statements across servers sample

INSERT into [target database name]. [dbo]. [Table name]
([target_id]
, [Target_name])
SELECT * FROM
OpenDataSource (' SQLOLEDB ', ' Data source= server; dbn= source database name; uid= user name; pwd= password '). source database name. dbo. [Table name]


But the above query needs to open the perimeter database query

First select the master database, create a new query, and execute the following SQL

External Account:

exec sp_configure ' show advanced options ', 1
Reconfigure
exec sp_configure ' Ad Hoc distributed Queries ', 1
Reconfigure

-------------------------------

Close the perimeter:

exec sp_configure ' show advanced options ', 0
Reconfigure
exec sp_configure ' Ad Hoc distributed Queries ', 0
Reconfigure

Query SQL statements across servers sample

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.