Accessing operations remote databases using SQL script

Source: Internet
Author: User

1  Use [Hik]2 GO3 /** * * * object:storedprocedure [dbo].    [Sp_test] Script date:08/21/2015 09:55:21 * * * * **/4 SETAnsi_nulls on5 GO6 SETQuoted_identifier on7 GO8 --Batch submitted through debugger:sqlquery17.sql|7|0| C:\users\a\appdata\local\temp\~vs6295.sql9 --Batch submitted through debugger:sqlquery14.sql|7|0| C:\users\a\appdata\local\temp\~vscdad.sqlTen -- ============================================= One --Author: <Author,,Name> A --Create Date: <create date,,> - --Description: <Description,,> - -- ============================================= the ALTER PROCEDURE [dbo].[sp_test] - @ServerName VARCHAR( -) -  as - BEGIN +      -     SETNOCOUNT on; +  A     --If you have frequent access or large amounts of data, it is recommended to use a linked server at  - --create a linked server - execsp_addlinkedserver@ServerName,' ','SQLOLEDB','' ; - execsp_addlinkedsrvlogin@ServerName,'false',NULL,'SA','251314' ; -  - --Query Example in --declare @tname varchar, @num int - --set @[email protected]+ '. Hik ' to --declare @sql Nvarchar (+) =n ' Select @num =count (*) from ' [email protected]+ '. dbo. Device '; + --Exec sp_executesql @sql, N ' @num int output ', @num output - --Select @num the  * Declare @sql Nvarchar(Max)=N'Select COUNT (*) from'+@ServerName+'. Hik.dbo.Device'; $ Execsp_executesql@sql;Panax Notoginseng  - --remove linked server after processing is complete the execSp_dropserver@ServerName,'droplogins';  +  A END

I also found on the Internet resources, and then modified a bit, to achieve the prototype of the requirements for your reference.

Accessing operations remote databases using SQL script

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: 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.