sql - Making triggers in mySQL -


i'm new triggers , mysql, , there question asked part of class make trigger support inserting new "invoice" apart of database, , automatically update customer in 'customer' table adding new invoice onto customer balance attribute.

sorry if question isn't clear can answer details need clarifying.

example of customer, , invoice table following.

create table customer (   id int,   ...   transaction_count int default 0 );  create table invoice (   id int,   customer_id int,    ... ); 

and trigger this.

delimiter  $$ create trigger invoice_counter after insert on invoice each row  begin   insert customer     set transaction_count = transaction_count + 1     id = new.customer_id; end $$ delimiter ; 

following link more useful.

create trigger in mysql

when need deeper on trigger

mysql trigger manual


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -