Copy a value from a Table by a Trigger to another table

1

I am creating a java app where the user will enter a value and then save said operation so that this value is recorded in a table. What I need is that this value by means of a trigger is copied into a table which does not auto-increment only a primary key and that every time a user adds a record that record is copied and "replaced" and adds to the previous value of the another table.

To explain it better:

I have a table called Entradadinero:

Code: Integer, Pk Autoinc pesosentrantes: Double

this table will be filled through an interface and by a user

Another table called "accumulated money"

Code: Integer: Pk Money Quantity: dobule ....................... What I hope through a trigger is to copy the value of pesenstrantes to the accumulated money table in its DineroCantidad field and add to the previous value if there is a value. In this last table as you will notice there is no autoincremental value since there should only be 1 single record (last entry) and already added to the previous one.

I searched the web for something like that but I have not managed to create a Trigger of these characteristics. If someone can help me very grateful. Excellent forum and Thanks in advance.

    
asked by Juan Perez 03.04.2018 в 03:37
source

1 answer

1

a possible trigger would be:

CREATE TRIGGER update_dineroacumulado UPDATE OF pesosentrantes ON Entradadinero 
  BEGIN
    UPDATE dineroacumulado SET DineroCantidad=DineroCantidad + new.pesosentrantes WHERE 1;
  END;

note WHERE 1 updates all rows, but assume that dineroacumulado has only one row

edit: there I fall that is in an insert test this other

CREATE TRIGGER update_dineroacumulado2 AFTER INSERT ON Entradadinero 
  BEGIN
    UPDATE dineroacumulado SET  DineroCantidad= DineroCantidad + 
    NEW.pesosentrantes WHERE 1;
 END;
    
answered by 03.04.2018 / 09:02
source