I have a table1 with columns (date, field1, field2, field3, field4, field5, field6, field7, field8)
I have another table2 with columns (date, field1,someothercolumns, field3, field5, field7, unrelatedcolumns1, someothercolumns2)
Now every time when new data is imported into table2, I also want data from columns (date, field1, field3, field5, field7) from table2 to automatically be copied into table1 (date, field1, field3, field5, field7).
Missing columns in table1 can have null values
Is it possible using trigger or any stored procedures?
Try something like this:
In a trigger, you can access the “pseudo” tables
Inserted(andDeletedforUPDATEandDELETEtriggers) which contains all rows that have been affected by the statement that caused the trigger to fire.This is important : if you have an
INSERTstatement that inserts 10 rows, your trigger will fire once and the pseudo tableInsertedwill have 10 rows in it. Do not ever assume that your trigger fires once per row that’s being inserted – that is not the case.So in this trigger here, whenever an
INSERTintotable2has happened, the columns in question are extracted from theInsertedpseudo table and inserted intotable1.Does that solve your problem?