Sql Query to Copy data between two Tables of different Database in SQL Server

Last Reply on Oct 10, 2017 04:31 AM By dharmendr

Posted on Oct 09, 2017 03:57 AM

Hi all,

i am facing some database daily routine issues. in my case i have two servers with two different databases tables.like,
Server Names are 'SOURCESERVER' and 'DESTINATIONSERVER' .

Under 'SOURCESERVER' i have database name 'SOURCEDATABASE', in this database i have 3 tables like 'SOURCEDB1', 'SOURCEDB2', 'SOURCEDB3'.

Under 'DESTINATIONSERVER' i have database name 'DESTINATIONDATABASE' in this database i have 2 tables like 'DESTINATIONDB1',
'DESTINATIONDB2'.

by using above database tables i want to copy 'SOURCEDB1' values in to 'DESTINATIONDB1' and from 'SOURCEDB2' 3 columns and
'SOURCEDB3' 2 columns in to 'DESTINATIONDB2'. 

my query is every day without doing any user access i want delete 'DESTINATIONDB1' and'DESTINATIONDB2' tables data and copy data from 'SOURCEDATABASE' tables in daily morning 8'O Clock.

How should i reach the above query. 

Thanks in advance 

Posted on Oct 10, 2017 04:31 AM

Hi nagaraju60,

Refer the sample query.

INSERT INTO [SchemaName].[YourTableNameHere]
SELECT * FROM [SourceServer].[SourceDatabase].[SchemaName].[YourTableNameHere]

Then use the query in Job Schedular to execute every day at specific time.

Automated Email Notifications using SQL Server Job Schedular