Triggers in between two different databases

  • I have a table tblClients in db1 database and also another table tblDemo in db2 database. When ever the insert or update operation done in tblclients table then the records will be inserted automatically into tblDemo in db2.

    How do i write a trigger between two databases.

  • You can do this by prefixing the table with the database name. For example, the trigger in db1 can run something like "INSERT INTO DB2.dbo.TableName(column1, column2)....".

    However, I would not recommend this. Cross database triggers may be little risky. If the other database is not available or busy, it can delay or abort your transactions.

    I would recommend replication or an asynchronous trigger using Service broker for this type of requirements.

    .

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply