SQL Server database inserts data across server queries

Source: Internet
Author: User

Distributed query for SQL Server: If a project requires two or more servers, and we have to remove the data from several servers, we must use distributed queries!
Here are two concepts: Local data source, remote data Source!
A local data source refers to data on a single server, while a remote data source refers to data on another SQL instance.
How do I take a number across servers?
One
If you have frequent access or large amounts of data, we recommend that you create a linked server with a linked server
exec sp_addlinkedserver ' srv_lnk ', ' ', ' SQLOLEDB ', ' Remote server name or IP address '
exec sp_addlinkedsrvlogin ' Srv_lnk ', ' false ', NULL, ' username ', ' password ' go

--query Example:
SELECT * from Srv_lnk. Database name. dbo. Table name

--Import Example:
SELECT * into table from Srv_lnk. Database name. dbo. Table name go--remove linked server when no longer in use

exec sp_dropserver ' srv_lnk ', ' droplogins '
Two
--if it's just temporary access, you can use OPENROWSET directly

--query Example:
SELECT * FROM OPENROWSET (' SQLOLEDB ', ' SQL Server name '; User name '; ' Password ", database name. dbo. Table name)
--Import Example:
SELECT * Into table from OPENROWSET (' SQLOLEDB ', ' SQL Server name '; User name '; ' Password ", database name. dbo. Table name)

How do I set it up in Enterprise Manager?
SQL Instance---> Security---> Linked server---> Right-click New Linked server General Enter the name of the linked server, select other data sources, select SQLOLEDB, Data source write, general IP address re-select Security-----"SELECT Local login----" The analog tick is made in this security context, and the user and password are entered.

FAQ: 1. After we have established the linked server, we do a query operation example: We have already made a link to the DFLD server, and then we want to access the authors table select * from DFLD in the pubs database. PUBS.. Authors often have two types of problems
1. Tip The heterogeneous query requires the ANSI_NULLS and ANSI_WARNINGS options to be set for the connection. This ensures consistent query semantics. Enable these options, and then re-issue your query. This hint is because the ANSI_NULLS is not opened with Ansi_warnings set ANSI_NULLS on set ANSI_WARNINGS on Select * from DFLD. PUBS.. authors--, that's it!
2. Tip A machine MSDTC service is not available This tip is simple, just open the MSDTC service! Note: The MSDTC service needs to be turned on both sides, and is not turned on by default

SQL Server database inserts data across server queries

Related Article

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.