SQL cross-Server Query statements

Source: Internet
Author: User
The two methods for cross-server SQL query are generally not available if the security settings are complete, but the internal network is still good.

The two methods for cross-server SQL query are generally not available if the security settings are complete, but the internal network is still good.

Select * from OPENDATASOURCE (
'Sqlodb ',
'Data Source = remote ip address; User ID = sa; Password = password'
). Database Name. dbo. Table Name

Insert local database name .. table name select * from OPENDATASOURCE (
'Sqlodb ',
'Data Source = remote ip address; User ID = sa; Password = password'
). Database Name. dbo. Table Name

Or use the connection Server:
-- Create linkServer
Exec sp_addrole server 'Alias ', '', 'sqloledb', '192. 168.2.5'

-- Log on to the linkServer
Exec sp_add1_srvlogin 'Alias ', 'false', null, 'sa', '123'

-- Query
Select * from alias. Database Name. dbo. Table Name

-- Delete the linked server when it is no longer in use
Exec sp_dropserver 'Alias ', 'droplogins'

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.