SQL Cross-server queries

Source: Internet
Author: User
Tags sql server books

Directly on the dry goods.

Grammar:

Select *  from OpenDataSource ('SQLOLEDB','Data source=your DB IP; User Id=username; Password=pwd'). DBName.dbo.TableName

Believe in this grammar. You can see at a glance what's going on here.

If error:

' Ad Hoc Distributed Queries ' ' Openrowset/opendatasource ' because this component has been shut down as part of this server's security configuration.
' Ad Hoc Distributed Queries '.
' Ad Hoc Distributed Queries ' For more information, see "Surface area Configurator" in SQL Server Books Online.

You can add a command that modifies the database configuration before the query statement, enabling the Ad Hoc distributed Queries

--Open Ad Hoc distributed Queries--Two reconfigure is a must.execsp_configure'Show advanced Options',1Reconfigureexecsp_configure'Ad Hoc Distributed Queries',1Reconfigure --T_sqlSelect *  from OpenDataSource('SQLOLEDB','Data source=your DB IP; User Id=username; Password=pwd'). DBName.dbo.TableName--re-close the Ad Hoc distributed Queriesexecsp_configure'Ad Hoc Distributed Queries',0Reconfigureexecsp_configure'Show advanced Options',0Reconfigure

This configuration entry requires that your current logged-on user has sufficient permissions: SA can: Local logins can also:

But how many direct uses of SA are there in the general project? In general, the DB_Owner for the database is not possible.

To administer permissions for the server: That is, the server role. You probably need sysadmin permission, right? Try it.

SQL Cross-server queries

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.