Search code examples
sqldatabasetransfer

How to insert table of one database to another database table automatically


I want to select data of SourceTable from SourceDatabase and insert summarized SourceTable into TargetDatabase TargetTable automatically (maybe every 4 hours).

It seems ok to use code below to insert the table manually:

    USE TargetDatabase
    GO
    INSERT INTO dbo.TargetTable(field1, field2, field3)
    SELECT field1, field2, field3
    FROM SourceDatabase.dbo.SourceTable
    WHERE (some condition) 

But I want every four hours run the query automatically. Is it possible?


Solution

  • You can use Jobs and schedule them as per your requirement