Tables in Remote Databases
You cannot create triggers on tables or views that reside outside the current database. You can, however, define a trigger on a local table whose trigger action manipulates a table in another database of the local server instance, or a table in a database of another server instance.
CREATE TRIGGER upd_nt UPDATE ON newtab REFERENCING NEW AS post FOR EACH ROW(UPDATE stores_demo@dbserver2:items SET quantity = post.qty WHERE stock_num = post.stock AND manu_code = post.mc);
- local trigger actions on a table in the local database
- cross-database trigger actions on a table in another database of the local server instance
- cross-server trigger actions on a table in a database of a remote server instance.
The cross-server triggered action of a trigger that is defined in a database of a remote server instance can be the event that activates one or more triggers in the local database, but in this case, triggered actions of the local trigger cannot be cross-server operations. If a SELECT, DELETE, INSERT, MERGE, or UPDATE statement from a remote database server is the event that activates a local trigger whose action specifies a table in a database of a remote server instance, the trigger actions fail.
-- Trigger action from dbserver1 to dbserver3: CREATE TRIGGER upd_nt UPDATE ON newtab REFERENCING NEW AS post FOR EACH ROW(UPDATE stores_demo@dbserver3:items SET quantity = post.qty WHERE stock_num = post.stock AND manu_code = post.mc); -- Triggering statement from dbserver2: UPDATE stores_demo@dbserver1:newtab SET qty = qty * 2 WHERE s_num = 5 AND mc = 'ANZ';The UPDATE statement above returns an error at run time, because a cross-server triggering event cannot trigger another cross-server action.