I'm using SQL Server 2008. I have two databases called Adb and Bdb. There is a common table called commonTable. How can I update Adb database every 15 minutes using the data from the same table in Bdb?

  • 4
    You need to explain what you mean. For example, do you want the contents of Bdb to completely overwrite Adb every time? Or are you more looking to merge (e.g. delete rows in A that have been deleted in B, update rows that have changed, insert rows that have been added)? If the latter, how do you identify a row in the tables? Can you provide schema and indicate the primary key? Dec 11, 2012 at 23:12

2 Answers 2


Without more specifics:


    SET col1 = B.col1 /* , ... */
    FROM Adb.dbo.commonTable AS A
    INNER JOIN Bdb.dbo.commonTable AS B
    ON A.key_col = B.key_col;

  INSERT Adb.dbo.commonTable(key_col, col1 /* , ... */)
    SELECT key_col, col1 /* , ... */
    FROM Bdb.dbo.commonTable AS B
    WHERE NOT EXISTS (SELECT 1 FROM Adb.dbo.commonTable
      WHERE key_col = B.key_col);

    FROM Adb.dbo.commonTable AS A
    LEFT OUTER JOIN Bdb.dbo.commonTable AS B
    ON A.key_col = B.key_col
    WHERE B.key_col IS NULL;

Now schedule that stored procedure every 15 minutes using a SQL Server Agent job.

Isolation, concurrency, error handling etc. are all additional considerations, but most concerns should be minor if this is the only process that writes to Adb. You might also consider a more concise MERGE command, but the syntax is daunting and it buys you less than you might expect in terms of improving concurrency and eliminating race conditions.

You might also want to consider transactional replication - get rid of this concept of having to do anything manually, and also the idea that data could be up to 15 minutes out of date.


I have 2 database with tables. I want to update 2nd database table when there is an insert in first database table . In first database when a row is inserted the values from that row shall get updated in second database table . (in first database table if employee_id and time is inserted then the same update shall happen in the second database table for same employee_id )

  • If you have a new question, please don't use Answer section. Post it a separate question
    – Arulkumar
    Aug 25, 2016 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.