Insert users into different databases

Asked

Viewed 48 times

0

I have two databases. Database A, and Database B. The user makes his registration in the database system A. I want to create a trigger for the same time, this registration also go to the database B, for him to have access to the other system, with the same data. It is possible?

  • Do you want to do this at the application or database level? It is possible in both ways, depending on the databases.

  • You could explain to me how it would work?

1 answer

2


In this case you use a transaction to ensure that the data will be 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 in entering the data in any of the tables it will come back (rollback) the whole operation.

  • But in this way, uilizando transaction is automated? Pq would have to be something like this: Every time a user is inserted into the database A, that user will automatically be inserted into the database B. To have access to both systems

  • This way it will insert in both or none. Suddenly what you are looking for is a Rigger that copies when saved?

  • I want something that when the person registers into the database system A, automatically this record goes into the database of the other system. With transaction would be manual right?

  • I don’t know how your English is, but would that be something more in the sense of that question? https://dba.stackexchange.com/questions/44758/create-a-trigger-to-update-table-data-on-another-servers-database

  • With transaction he makes the Insert in both, not copies from one to the other.

  • 1

    I’ll read the article, and see if transaction suits me. But you already helped me dms!! Thank you!

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.