Paste a trigger copy of a row into another repeating table in SQL Server 2008

Overview. . Trying to write a trigger for a SQL Server 2008 database. TableA and TableB share the same schema.

Purpose: On a tab in TableA copy everything in this row to a new row in TableB

Notes:

Using this question I manage to get the most out of it, but then came across a problem with

You cannot use text, text, or graphic columns in the “inserted” and “deleted” tables.

I only have text columns, but I also want to copy them.

I found this website that seems to have a workaround, but it is working on an update, and I was not able to apply this with my insert example ...

Any ideas?

Edit : the goal is to add functionality to an existing product, unfortunately, I cannot change the TableA schema.

+4
source share
1 answer

I am not sure why you cannot use the example you are associated with. It should be simple:

 CREATE TRIGGER T_TableA_I on TableA after insert as set nocount on insert into TableB (ColumnA,ColumnB,/* Columns in table b */) select a.ColumnA,a.ColumnB, /* Columns from table a */ from TableA a inner join inserted i on a.PKColumn1 = i.PKColumn1 and a.PKColumn2 = i.PKColumn2 /* Primary Key columns from table A */ 

Of course, your question does not contain table definitions, so the above will need to be slightly modified. Hope you can decide what to add / remove from above where comments exist.

+7
source

Source: https://habr.com/ru/post/1402568/


All Articles