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','192.168.1.9' ; - 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