The code is as follows:
DECLARE @serverName VARCHAR( -)DECLARE @ip VARCHAR( -)DECLARE @dbName VARCHAR( -)DECLARE @userName VARCHAR( -)DECLARE @userpassword VARCHAR( -)SET @serverName = 'Dblinkname' --DB link NameSET @ip = '120.79.36.65' --IP required to connect to the serverSET @dbName = 'DbName' --the name of the database to which the server should be connectedSET @userName = 'SXi' --need to connect to the server's accountSET @userpassword = '***' --password required to connect to the serverEXECMaster.dbo.sp_addlinkedserver@server = @serverName,@srvproduct=@serverName,@provider=N'SQLNCLI',@datasrc=@ip,@catalog=@dbNameEXECMaster.dbo.sp_addlinkedsrvlogin@rmtsrvname=@serverName,@useself=N'False',@locallogin=NULL,@rmtuser=@userName,@rmtpassword=@userpasswordEXECMaster.dbo.sp_serveroption@server=@serverName,@optname=N'RPC',@optvalue=N'true'EXECMaster.dbo.sp_serveroption@server=@serverName,@optname=N'RPC out',@optvalue=N'true'
PCB SQL Server Code creation Dblink