0

I have a Microsoft SQL Server 2012 with a table called for example 'Tasks' which is used by a 3rd party solution. I have the same same with one additional row "change_type" in another DB.

I want to copy the affected row on an INSERT, UPDATE or DELETE from the source to the destionation table additionally with the info in the column 'change_type' if it was an isert, update or delete.

How can i do this in Microsoft SQL Server 2012?

STORM
  • 4,005
  • 11
  • 49
  • 98
  • 1
    You've added tag 'trigger' so clearly you know a trigger is required. What have you tried so far? – Nick.Mc Aug 13 '16 at 09:03
  • Hi, Nick. yes i know that it is possible to have triggers within a AB. But i have never worked before. I found this article on MSDN https://msdn.microsoft.com/de-de/library/ms189799.aspx but i did not understand how to create it and how to act on an event so that the affected row is copied to the destination table. – STORM Aug 13 '16 at 09:49
  • This looks like a good example of what you're after - why don't you have a go. https://sql-box.com/2011/07/10/track-dml-changes-using-after-trigger-for-update-delete-and-insert-rows-capture-changed-data-rows-using-t-sql/ then return and ask any specific questions when you have trouble. – Nick.Mc Aug 13 '16 at 23:51
  • 1
    Is something like [this](http://stackoverflow.com/questions/11890868/how-to-store-historical-records-in-a-history-table-in-sql-server/11891352#11891352) what you are looking for? – HABO Aug 14 '16 at 03:33
  • @HABO: Yes this is what i wanted. Thank you! – STORM Aug 18 '16 at 12:12

0 Answers0