SQL Server Cross-server access data

Source: Internet
Author: User
-- 1. Use OpenRowSet directly
Create view name
As

Select * From OpenRowSet ('sqlodb', 'Another server name'; 'sa '; 'Password', database name. DBO, table name)

 

-- 2. Use the linked server

-- Create a connection server to access another server in the Enterprise Manager.

-- Or directly use the following statement to establish a connection server (srv_lnk is the name of the linked server, you can modify it on your own)
Exec sp_addmediaserver 'srv _ lnk ', '', 'sqlodb', 'remote server name or IP address'
Exec sp_add1_srvlogin 'srv _ lnk ', 'false', null, 'username', 'Password'
Go

-- Then you can create a view.
Create view name
As

Select * From srv_lnk. Database Name. DBO, table name

 

Example:

Select .*
From OpenRowSet ('sqloledb', '192. 168.0.200 '; 'sa'; 'pass ',

'Select * from pubs. DBO. Authors order by au_lname, au_fname ') as

 

Complete.

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.