Data transfer between different database servers

Source: Internet
Author: User

Method One:

1.select top 1000* from OpenDataSource (' SQLOLEDB ', ' Data source= database server IP address; User id= account; password= password '). Database name. dbo. data table

Example: Select Top 1000* from OpenDataSource (' SQLOLEDB ', ' Data source=59.188.1.140; User Id=sa; password=led123456 '). Pgenius.dbo.NEWS_MAIN

If an error is performed,

Cause: "SQL Server blocked access to component ' Ad Hoc distributed Queries ' STATEMENT ' Openrowset/opendatasource" when replicating data from a remote server to local Because this component has been shut down as part of this server's security configuration. System administrators can enable ' Ad Hoc distributed Queries ' by using sp_configure. For more information about enabling ' Ad Hoc distributed Queries ' ERROR

Execute the following code:

Enable AD Hoc distributed Queries:

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

Close AD Hoc distributed Queries:

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

Method Two:

2.

  --1.0 Create a database link to a remote connection, which is an alias

EXEC sp_addlinkedserver ' ServerA ', ' ', ' SQLOLEDB ', ' Server IP address '

EXEC sp_addlinkedsrvlogin ' ServerA ', ' false ', NULL, ' sa ', ' sa account password '

Such as:

EXEC sp_addlinkedserver ' ServerA ', ', ' SQLOLEDB ', ' 127.1.0.1 '

EXEC sp_addlinkedsrvlogin ' ServerA ', ' false ', NULL, ' sa ', ' 123 '

 --2.0 Executing query statements

2.0.1: Direct Query

Select top 1* from [ServerA]. [Database name]. [dbo]. [Data table name]

2.0.2: Even table query

Select top 1* from [ServerA]. [Yao]. [dbo]. [News_main] as M inner join [ServerA]. [Yao]. [dbo]. [News_content] as C on m.id=c.id

2.0.3: Collecting data

--If the structure of table A and table B is the same,
INSERT into TableB SELECT * from ServerA.DatabaseA.dbo.TableA

--if the structure part of table A and table B is the same, then
INSERT into TableB (the column names that need to be copied, separated by commas) SELECT the list that needs to be copied, separated by commas from ServerA.DatabaseA.dbo.TableA

  

Data transfer between different database servers

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.