Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating trigger across different databases

Is there any way to create triggers on different databases? my requirement is like:-

 database: a1.db consist table: t1
 database:a2.db  consist table: t2

now i have to use trigger on t1 (whenever any delete and update operation) happens on t1 a value has to be inserted into t2.

waiting for your feedback...

like image 340
Abhimanyu Avatar asked Nov 16 '25 07:11

Abhimanyu


2 Answers

I can only speak for MySQL, but you should be able to do something like:

CREATE TRIGGER ad_t1 AFTER DELETE ON `a1.db`.t1
FOR EACH ROW
INSERT INTO `a2.db`.t2 VALUES (...)
like image 60
Josh Davis Avatar answered Nov 18 '25 21:11

Josh Davis


What are the other databases you are using besides mysql? If Oracle is one of them, then you can create dblinks from Oracle to the other databases, and your trigger (running on Oracle) could use those dblinks to update the tables in the other databases.

You can refer to this link for info on creating dblinks in Oracle: http://download.oracle.com/docs/cd/B12037_01/server.101/b10759/statements_5005.htm

Also, see this link (How to create a DB link between two oracle instances) for another answer on stackoverflow.

like image 31
dcp Avatar answered Nov 18 '25 19:11

dcp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!