[SQL Server] [basic] link Server

Source: Internet
Author: User

/*
Environment:

Local (XP + sql2005 ):
Select @ version

Icrosoft SQL Server 2005-9.00.1399.06 (Intel x86)
Oct 14 2005 00:33:37
Copyright (c) 1988-2005 Microsoft Corporation
Developer Edition on Windows NT 5.1 (build 2600: Service Pack 3)

Data Server (Win2000 + SQL2000 ):
Select @ version

Microsoft SQL Server 2000-8.00.2039 (Intel x86)
May 3 2005 23:18:38
Copyright (c) 1988-2003 Microsoft Corporation
Enterprise Edition on Windows NT 5.0 (build 2195: Service Pack 4)

*/
-- 1 create a linked server
Exec sp_addrole server 'data', '', 'sqloledb', '192. 168.102.208'
Exec sp_add1_srvlogin 'data', 'false', null, 'sa ', 'sa'
Go
-- 2 create a test process
If object_id ('P _ test') is not null drop proc p_test
Go
Create proc p_test @ SQL varchar (8000)
As
Begin
Exec (@ SQL)
End
-- 3 Test
Declare @ SQL varchar (8000)
Set @ SQL ='
Delete from data. master. DBO. TB
Insert data. master. DBO. Tb (item) values (''aaaaaaaaa '')
Select item from data. master. DBO. tb'
Exec p_test @ SQL

/*
(One row is affected)

(One row is affected)
Item
Bytes ----------------------------------------------------------------------------------------------------
Aaaaaaaaaa

(One row is affected)
*/

-- 4 delete a link
Exec sp_dropserver 'data', 'droplogins'

 

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.