SQL Sever cross-Library query

Source: Internet
Author: User

execsp_configure'Show advanced Options',1Reconfigureexecsp_configure'Ad Hoc Distributed Queries',1ReconfigureSelect *  from OpenRowset('SQLOLEDB','192.168.1.180';'SA';'123.com', Joyblessing.dbo.User_Lottery)execsp_configure'Ad Hoc Distributed Queries',0Reconfigureexecsp_configure'Show advanced Options',0Reconfigure

StatementSELECT *  fromDatabase a.dbo. Table A, database b.dbo. Table b bWHEREA.field=B.field "DBO" can be omitted asSELECT *  fromDatabase A.. Table A, database B.. Table b bWHEREA.field=b.fieldsqlserver Database:--the phrase is to map a remote databaseEXECsp_addlinkedserver'the IP or host name of the remote database'N'SQL Server'--This is the log in to the remote databaseEXECsp_addlinkedsrvlogin'the IP or host name of the remote database','false',NULL,'Login Name','Password'--after you log on, you can manipulate objects in the remote database in the following formatSelect *  from [the IP or host name of the remote database].[Database name].[dbo].[Table name] Insert  into OpenRowset('SQLOLEDB','192.168.0.100';'SA';'10060','SELECT * from Knss2009.dbo.yw_kck')Select *  fromYw_kck++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++data operations between different server databases--create a linked serverexecsp_addlinkedserver'ITSV',' ','SQLOLEDB','remote server name or IP address' execsp_addlinkedsrvlogin'ITSV','false',NULL,'User name','Password' --Query ExampleSelect *  fromitsv. Database name. dbo. Table name--Import SampleSelect *  intoTable fromitsv. Database name. dbo. Table name--remove linked server when no longer in useexecSp_dropserver'ITSV','droplogins' --connecting remote/LAN data (Openrowset/openquery/opendatasource)--1, OpenRowset--Query ExampleSelect *  from OpenRowset('SQLOLEDB','SQL Server name';'User name';'Password', database name. dbo. Table name)--Raw Cost surfaceSelect *  intoTable from OpenRowset('SQLOLEDB','SQL Server name';'User name';'Password', database name. dbo. Table name)--Importing a local table to a remote tableInsert OpenRowset('SQLOLEDB','SQL Server name';'User name';'Password', database name. dbo. Table name)Select * fromLocal Tables--Updating local tablesUpdatebSetB. Column A=A. Column A from OpenRowset('SQLOLEDB','SQL Server name';'User name';'Password', database name. dbo. Table name) asAInner JoinLocal Table B onA.column1=B.column1--OPENQUERY usage requires creating a connection--Create a linked server by creating a connection firstexecsp_addlinkedserver'ITSV',' ','SQLOLEDB','remote server name or IP address' --EnquirySelect *  from OpenQuery(ITSV,'SELECT * from database. dbo. Table name') --Importing a local table to a remote tableInsert OpenQuery(ITSV,'SELECT * from database. dbo. Table name') Select *  fromLocal Tables--Updating local tablesUpdatebSetB. Column B=A. Column B from OpenQuery(ITSV,'SELECT * from database. dbo. Table name') asaInner JoinLocal surface B onA. Column A=B. Column A--3, Opendatasource/openrowsetSELECT   *  from   OpenDataSource('SQLOLEDB','Data Source=ip/servername; User id= login name; password= Password'). Test.dbo.roy_ta--Importing a local table to a remote tableInsert OpenDataSource('SQLOLEDB','Data Source=ip/servername; User id= login name; password= Password'). database. dbo. Table nameSelect *  from

SQL Sever cross-Library query

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.