Mysql temporary table

Asked

Viewed 428 times

-1

How to assign an update to a temporary table in my case I do an update right at the beginning, create a temporary table and then a Rigger(trigger) in this trigger I try to assign the values changed by the update to the temporary table and then I select in the temporary table but it always comes empty even I change a record in the table and run the update

Code:

 MySqlCommand queryCommand = new MySqlCommand("UPDATE fl_produtos SET  ativo_adwords = '0' where produto_quantidade = @produtoQuantidade", conn);
                queryCommand.Parameters.Add("@produtoQuantidade", MySqlDbType.Int32);
                queryCommand.Parameters["@produtoQuantidade"].Value = 0;



               MySqlCommand queryCommand1 = new MySqlCommand("CREATE TEMPORARY TABLE Produtos_Desativados AS (SELECT produto_nome, produto_quantidade, ativo_adwords, idfabricante FROM fl_produtos) ENGINE=MEMORY;", conn);

                MySqlCommand queryCommand2 = new MySqlCommand("DELIMITER CREATE TRIGGER Tgr_ProdutosDesativados_Update AFTER UPDATE ON fl_produtos FOR EACH ROW BEGIN INSERT INTO Produtos_Desativados SET ativo_adwords = OLD.ativo_adwords, produto_nome = OLD.produto_nome, idfabricante = OLD.idfabricante, produto_quantidade = OLD.produto_quantidade END; DELIMITER", conn);

                MySqlCommand queryCommand3 = new MySqlCommand("SELECT produto_nome, produto_quantidade, ativo_adwords, idfabricante FROM Produtos_Desativados", conn);
  • You could explain better, I don’t understand what you need.

  • 1

    Please put the commands in the order they are being executed.

  • 1

    @Osvaldo didn’t understand what you meant?

  • 1

    @downvoter: Repeating what you have already written, and it was not understood, will not do you any good.

  • 1

    @downvoter: Why with commands being executed in the displayed order there was no trigger (Trigger) at the time of UPDATE execution and therefore there would be no way to fire it.

1 answer

1


Unable to create triggers with temporary tables.

Taken from mysql manual

You cannot associate a Trigger with a TEMPORARY table or a view.

Browser other questions tagged

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