Create and delete a linked server in the SQL Server database

Source: Internet
Author: User

/***** Object: linkedserver [202.99.213.226] script Date: 06/26/2007 21:34:35 ******/
Exec master. DBO. sp_addmediaserver @ Server = n'nfdrp', @ srvproduct = n' SQL Server'
/* For security reasons the linked Server Remote logins password is changed ########*/
Exec master. DBO. sp_add1_srvlogin @ rmtsrvname = n' 202. 99.213.226 ', @ useself = n'false', @ locallogin = NULL, @ rmtuser = n'sa', @ rmtpassword = '########'

Go
Exec master. DBO. sp_serveroption @ Server = n' 202. 99.213.226 ', @ optname = n' collation compatible', @ optvalue = n' false'
Go
Exec master. DBO. sp_serveroption @ Server = n' 202. 99.213.226 ', @ optname = n' data access', @ optvalue = n' true'
Go
Exec master. DBO. sp_serveroption @ Server = n' 202. 99.213.226 ', @ optname = n' dist', @ optvalue = n' false'
Go
Exec master. DBO. sp_serveroption @ Server = n' 202. 99.213.226 ', @ optname = n' pub', @ optvalue = n' false'
Go
Exec master. DBO. sp_serveroption @ Server = n' 202. 99.213.226 ', @ optname = n' RPC', @ optvalue = n' false'
Go
Exec master. DBO. sp_serveroption @ Server = n' 202. 99.213.226 ', @ optname = n' RPC out', @ optvalue = n' false'
Go
Exec master. DBO. sp_serveroption @ Server = n' 202. 99.213.226 ', @ optname = n' sub', @ optvalue = n' false'
Go
Exec master. DBO. sp_serveroption @ Server = n' 202. 99.213.226 ', @ optname = n' connect timeout', @ optvalue = n' 0'
Go
Exec master. DBO. sp_serveroption @ Server = n' 202. 99.213.226 ', @ optname = n' collation name', @ optvalue = NULL
Go
Exec master. DBO. sp_serveroption @ Server = n' 202. 99.213.226 ', @ optname = n' lazy schema valider', @ optvalue = n' false'
Go
Exec master. DBO. sp_serveroption @ Server = n' 202. 99.213.226 ', @ optname = n' query timeout', @ optvalue = n' 0'
Go
Exec master. DBO. sp_serveroption @ Server = n' 202. 99.213.226 ', @ optname = n' use remote collation', @ optvalue = n' false'

The above is the link ServerCodeThe following code deletes the server:
---------------------------
/***** Object: linkedserver [202.99.213.226] script Date: 06/26/2007 21:50:58 ******/
If exists (select srvname from Master. DBO. sysservers SRV where srvid! = 0 and srvname = n' 202. 99.213.226 ') exec master. DBO. sp_dropserver @ Server = n' 202. 99.213.226', @ droplogins = 'droplogins'

-----------------------------------
Query example
Select * from [202.99.213.226]. nafine1129.dbo. biarea

---------------------
Select top 10 *
From
OpenDataSource ('sqloledb', 'Data source = 202.99.213.226; user id = sa; Password = nafineyxb '). nafine1129.dbo. biarea

--------- This is a pure command method. For more information about this aspect, see Microsoft's help. Microsoft's help is indeed good.

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.