October 28, 2005 at 1:30 pm
I have a database with two tables. I'll call then table1 and table2 to ease.
When data has been inserted (after Insert) into table1, I need to transfer new records in table2 to one of several remote database based on a remoteID field in table2
i was thinking I could use an after insert trigger on table1, but do not know how to set up variables in triggers.
Can anyone provide an example for me?
Thanks,
Ron
October 28, 2005 at 2:01 pm
What do you mean set up variables?
And when records are inserted into table1, how do you know there are new records in table 2?
Is ther some kind of relationship between the tables?
There is no difference between variables in triggers or stored procedures.
When creating a trigger you need to understand the use of the Inserted/deleted tables
Please post additional information, like create example table statements, and some sample data.
From Books online
deleted and inserted are logical (conceptual) tables. They are structurally similar to the table on which the trigger is defined, that is, the table on which the user action is attempted, and hold the old values or new values of the rows that may be changed by the user action. For example, to retrieve all values in the deleted table, use:
SELECT *FROM deleted
October 28, 2005 at 2:18 pm
Please be aware that implimenting this requirement via triggers is a very bad idea because if any of the remote databases are not available, the local trigger will not allow the transaction to complete.
Consider using database replication as a solution.
SQL = Scarcely Qualifies as a Language
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply