Create Trigger to update table of BANK 2 when changing table of BANK 1

0

I have several databases BANK_1 (Main) BANK_2, _3, _4 ... (Companies). In every bank there is a company table, who have the same structure, in BANK_1 I have the company register of all BANK_2, _3, _4 ...! I would like to update any company information in BANCO_1, the data would be updated in the company table of BANCO_2 or _3 or _4.

Ex: I upgraded Company Code 1 to BANCO_1, this company's information was updated on its bank.

I wanted to use a Trigger, but I'm not very familiar with the process. I'm using MySql.

Company Table BANK_1 (Main):

CompanyTableBANCO_2(Company):

CompanyTableBANCO_3(Company):

Can this be done?

I was able to edit and edit by editing the Main Base as follows:

DELIMITER $$
  USE 'projects'$$
  DROP TRIGGER /*!50032 IF EXISTS */ 'empresas_iguais'$$
  CREATE
  /*!50017 DEFINER = 'root'@'localhost' */
    TRIGGER 'empresas_iguais' AFTER UPDATE ON 'cs_empresas' 
    FOR EACH ROW UPDATE empresaum.cs_empresas 
    SET empresaum.cs_empresas.empresa_razao_social = 
    NEW.empresa_razao_social, 
      empresaum.cs_empresas.empresa_nome_fantasia = 
      NEW.empresa_nome_fantasia,
      empresaum.cs_empresas.empresa_db_host = NEW.empresa_db_host,
      empresaum.cs_empresas.empresa_db_user = NEW.empresa_db_user,
      empresaum.cs_empresas.empresa_db_password = NEW.empresa_db_password,
      empresaum.cs_empresas.empresa_db_nome = NEW.empresa_db_nome,
      empresaum.cs_empresas.empresa_tipo = NEW.empresa_tipo,
      empresaum.cs_empresas.empresa_cnpj_cpf = NEW.empresa_cnpj_cpf,
      empresaum.cs_empresas.empresa_contato = NEW.empresa_contato,
      empresaum.cs_empresas.empresa_email = NEW.empresa_email,
      empresaum.cs_empresas.empresa_telefone = NEW.empresa_telefone,
      empresaum.cs_empresas.empresa_celular = NEW.empresa_celular,
      empresaum.cs_empresas.empresa_logo = NEW.empresa_logo,
      empresaum.cs_empresas.empresa_registro = NEW.empresa_registro,
      empresaum.cs_empresas.empresa_level = NEW.empresa_level,
      empresaum.cs_empresas.empresa_status = NEW.empresa_status
    WHERE empresaum.cs_empresas.empresa_id = NEW.empresa_id;
   $$
DELIMITER;

Where empresaum Is the bank BANK_1. How can I put this value empresaum dynamic, according to the company_db_name field that exists in the company register, thus making it update the company in the bank that it is registered? Can someone give a light? Please!

    
asked by anonymous 07.09.2018 / 17:57

0 answers