IF NOT EXISTS(SELECT * FROM master.dbo.sysservers
WHERE srvname='OnlineSqlServerName')
BEGIN
EXEC sp_addlinkedserver 'OnlineSqlServerName',N'Sql server'
END
EXEC sp_addlinkedsrvlogin 'OnlineSqlServerName','false','sa','OnlineSqlUser','onlineSqlPwd'
INSERT INTO [OnlineSqlServerName].OnlineDatabase.dbo.OnlineTable(column1,column2,column3,column4,column5,column6)
SELECT column1,column2,column3,column4,column5,column6
from [dbo].[LocalTable]
Example:
---------------------
IF NOT EXISTS(SELECT * FROM master.dbo.sysservers
WHERE srvname='898.9.999.996')
BEGIN
EXEC sp_addlinkedserver '898.9.999.996',N'Sql server'
END
EXEC sp_addlinkedsrvlogin '898.9.999.996','false','sa','Retailuser','ms12345'
INSERT INTO [898.9.999.996].dbRetail.dbo.Mst_EmployeeMast(EmpName,Addresss,city,mob,dob,statuss)
SELECT EmpName,Addresss,city,mob,dob,statuss
from [dbo].[EMP]
WHERE srvname='OnlineSqlServerName')
BEGIN
EXEC sp_addlinkedserver 'OnlineSqlServerName',N'Sql server'
END
EXEC sp_addlinkedsrvlogin 'OnlineSqlServerName','false','sa','OnlineSqlUser','onlineSqlPwd'
INSERT INTO [OnlineSqlServerName].OnlineDatabase.dbo.OnlineTable(column1,column2,column3,column4,column5,column6)
SELECT column1,column2,column3,column4,column5,column6
from [dbo].[LocalTable]
Example:
---------------------
IF NOT EXISTS(SELECT * FROM master.dbo.sysservers
WHERE srvname='898.9.999.996')
BEGIN
EXEC sp_addlinkedserver '898.9.999.996',N'Sql server'
END
EXEC sp_addlinkedsrvlogin '898.9.999.996','false','sa','Retailuser','ms12345'
INSERT INTO [898.9.999.996].dbRetail.dbo.Mst_EmployeeMast(EmpName,Addresss,city,mob,dob,statuss)
SELECT EmpName,Addresss,city,mob,dob,statuss
from [dbo].[EMP]