简体   繁体   中英

how to create trigger in mysql for insert data into table

Leave_applied_table:

leave_applied_id  employee_id   status    start_date       end_date_session   hours
1                    345           1      2016-6-25          2016-8-25        16

Leave_actula_table:

leave_applied_id    leave_type_id    hours   created_at
345                  2                  16      2016-7-25
345                  2                  16      2016-7-25 
345                  2                 16       2016-7-25


Leave_approval_table:
leave_approval_id      leave_applied_id   manger_id    status
56                        345               125           1

this is my three table i have to create triggger like when i insert in to Leave_applied then in leave_actual table three row should insert and in leave_approval_table in entry should come as given data in table please suggest me how to write query for this how to create trigger i am new in one this please suggest me for give issue .

Try it like this:

DELIMITER $$
CREATE TRIGGER insert_trigger
BEFORE INSERT ON Leave_applied_table FOR EACH ROW
begin
     insert into Leave_actula_table (Leave_actula_table.leave_applied_id,and so ON....) values(new.employee_id,new.leave_type_id) ;

     insert into Leave_approval_table (Leave_approval_table.leave_applied_id, and so on....) values (new.employee_id and so on;

END;
$$
DELIMITER ;

Hope it helps you as a guide..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM