2

Consider Database 1 & Database 2 having a single table each Table 1 & Table 2

How is it possible to update table 1 inserting/updating/deleting any change that happens to Table 2?

Ben Löffel
  • 931
  • 4
  • 12
  • 29
  • Which [DBMS](https://en.wikipedia.org/wiki/DBMS) are you using? Postgres? Oracle? –  Jun 01 '17 at 13:27
  • Please tag your DBMS (SQL server, MySQL, Oracle) and the version. – JohnHC Jun 01 '17 at 13:27
  • Are they on the same server? – Shawn Jun 01 '17 at 13:28
  • @Shawn, no they are on separate servers. – Ben Löffel Jun 01 '17 at 13:29
  • If they are on different servers, I believe you'll have to set up a trusted relationship between the two for them to be able to talk to each other. Then it should just be a simple matter of running an UPDATE script on database1 that refers to .Database2..Table2. EDIT: Missed the part about updating changes. I was going on a 1-time change idea. Yes, cross db trigger would probably be best. – Shawn Jun 01 '17 at 13:32
  • 1
    Look into Federated Storage Engine. https://dev.mysql.com/doc/refman/5.7/en/federated-storage-engine.html – Shawn Jun 01 '17 at 13:45
  • Helpful! Thanks @Shawn – Ben Löffel Jun 01 '17 at 14:02

2 Answers2

4

You can just do a cross database trigger.

If you're using SQL server you can read here: Sql Server Trigger between 2 databases

If you're using Mysql you can read here: Cross database trigger in Mysql

Avitus
  • 15,640
  • 6
  • 43
  • 53
0

Perhaps create a view showing both tables?

CREATE VIEW my_view AS
SELECT * FROM db1.Table1, db2.Table2

Any change happening at any of the tables will be shown on the view, I hope it's what you wanted~

OmerM25
  • 243
  • 2
  • 13
  • Creating a view will help me see the difference between each table, however I am looking for a solution to have a Table 1 receive all the changes done remotely on Table 2. – Ben Löffel Jun 01 '17 at 13:38