SQL SERVER 2008 Queries other databases

Source: Internet
Author: User

1. Access other local databases

--Enable ad Hoc distributed queries--execsp_configure'Show advanced Options',1Reconfigureexecsp_configure'Ad Hoc Distributed Queries',1Reconfigure--Close AD Hoc distributed queries--When you are finished usingexecsp_configure'Ad Hoc Distributed Queries',0Reconfigureexecsp_configure'Show advanced Options',0Reconfigure--SELECT * from OpenDataSource (' SQLOLEDB ', ' Data source=ip (or servername); User id= login name; password= password '). database. dbo. Table name (or view)SELECT *  from          OpenDataSource(          'SQLOLEDB',            'Data Source=itvs; User Id=sa; Password=sa')               . ANSVSP.dbo.serv

2. Access databases on other machines

(1) Remotely open SQL Server on the remote machine

(2) Turn off the firewall on the remote machine

SELECT *  from          OpenDataSource (          'SQLOLEDB',            'Data source=192.168.1.26 ;               ' )               . ANSVSP.dbo.serv

Inline

SELECTA.bah,a.mz,b.*  from          OpenDataSource(          'SQLOLEDB',            'Data source=192.168.1.26; User Id=sa; Password=sadan')               . ANSVSP.dbo.serv asAInner JoinDb_local_table b onA.bah=b.id collate Chinese_prc_90_ci_ai;--Collate Chinese_prc_90_ci_ai keep the collation uniform on both sides of the equals sign

SQL SERVER 2008 Queries other databases

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.