I am trying to create a generic trigger in SQL Server which can copy all column data from Table A and insert them in corresponding fields in Table B.
There are few problems I am facing.
I need this copy to occur under three conditions : INSERT
, DELETE
and UPDATE
.
The trigger needs to be triggered after CUD operations. using AFTER throws SQL error saying
ntext
etc are not supported in inserted. How do I resolve this error?Instead of if used can work for
INSERT
but not for delete. Is there a way to do this for delete operations?Is there a way I can write a generic code inside the trigger which can work for all sorts of tables (we can assume that all the columns in table a exists in column b)
I am not well versed with triggers or for that matter DDL in SQL Server.
Appreciate if some can provide me some solutions.
Thanks Ben
CREATE TRIGGER (Transact-SQL)
nvarchar(max)
instead ofntext
.instead of
trigger for delete.