Insert users into different database

0

I have two Database. Database A, and Database B. The user makes his registration in the data bank system A. I want to create a trigger for the same time, this register also go to database B, so that it has access to the other system, with the same data. Is it possible?

    
asked by anonymous 28.06.2018 / 22:29

1 answer

2

In this case, you use a transaction to ensure that data is entered in both banks. The insertion will be done once in each one. In MySQL it looks like this:

BEGIN;
INSERT INTO badatabaseA.users (username, password)
    VALUES('test', 'test');
INSERT INTO badatabaseB.users (username, password) 
    VALUES('test','test');
COMMIT;

As we are using a transaction, if there is a problem inserting the data into any of the tables it will roll back the entire operation.

    
28.06.2018 / 22:44