Professional Documents
Culture Documents
3.7 Trigger Procedure: Performed On Table Payment. Futhermore The Updated Record Is Inserted Into Table Payment - Info
3.7 Trigger Procedure: Performed On Table Payment. Futhermore The Updated Record Is Inserted Into Table Payment - Info
7 Trigger Procedure
(1)The trigger paymentinfo_trg executed automatically AFTER UPDATE operation is
performed on table payment. Futhermore the updated record is inserted into table
payment_info.
mysql> delimiter //
mysql> create trigger paymentinfo_trg after update on payment for each row begin insert into
payment_info values(old.payId,new.payAmt,old.payAmt);end //
mysql> delimiter ;
+-------+------------+------------+
+-------+------------+------------+
| P3 | 10000 | 0|
+-------+------------+------------+
performed on table customer. Futhermore the new inserted record is inserted into table
cust_info.
mysql> delimiter //
mysql> create trigger cust_trg after insert on customer for each row begin insert into
cust_info(custId,firstName,lastName,custNrc,custPhone,custAddress,custEmail,custPassword)
values(new.custId,new.firstName,new.lastName,new.custNrc,new.custPhone,new.custAddress,n
ew.custEmail,new.custPassword);end //
mysql> delimiter ;
+--------+-----------+----------+--------------------+-------------+--------------+-----------------------
+--------------+---------------------+
+--------+-----------+----------+--------------------+-------------+--------------+-----------------------
+--------------+---------------------+
performed on table payment. If the number of seat is invalid,set the invalid seat number
+-------+--------+----------+--------+---------+
+-------+--------+----------+--------+---------+
| P1 | C1 | 2 | 30000 | 13.9.19 |
| P2 | C2 | 2 | 25000 | 13.9.19 |
| P3 | C3 | 0 | 10000 | 3.9.19 |
| P4 | C4 | 1 | 10000 | 3.9.19 |
| P5 | C5 | -1 | 10000 | 20.9.19 |
+-------+--------+----------+--------+---------+
mysql> delimiter //
mysql> create trigger seat_trg before insert on payment for each row begin if new.noOfSeat < 0
then set new.noOfSeat=0; end if;end //
+-------+--------+----------+--------+---------+
+-------+--------+----------+--------+---------+
| P1 | C1 | 2 | 30000 | 13.9.19 |
| P2 | C2 | 2 | 25000 | 13.9.19 |
| P3 | C3 | 0 | 10000 | 3.9.19 |
| P4 | C4 | 1 | 10000 | 3.9.19 |
| P5 | C5 | -1 | 10000 | 20.9.19 |
| P6 | C5 | 0 | 10000 | 20.9.19 |
+-------+--------+----------+--------+---------+
performed on table customer. Futhermore the deleted record is deleted from table
cust_info.
+--------+-----------+----------+--------------------+-------------+--------------+----------------
+--------------+---------------------+
+--------+-----------+----------+--------------------+-------------+--------------+----------------
+--------------+---------------------+
mysql> delimiter //
mysql> create trigger deletecust_trg after delete on customer for each row begin delete from
cust_info where custId=old.custId;end //
mysql> delimiter ;
+--------+------------+------------+---------------------+-------------+-------------+----------------------
+--------------+
+--------+------------+------------+---------------------+-------------+-------------+----------------------
+--------------+
+--------+------------+------------+---------------------+-------------+-------------+----------------------
+--------------+
performed on table customer. Futhermore the deleted record is recorded into table
mysql> delimiter //
mysql> create trigger delCust_trg before delete on customer for each row begin insert into
delCust_info(custId,firstName,lastName,custNrc)
values(old.custId,old.firstName,old.lastName,old.custNrc);end //
+--------+------------+------------+---------------------+-------------+-------------+----------------------
+--------------+
+--------+------------+------------+---------------------+-------------+-------------+----------------------
+--------------+
+--------+------------+------------+---------------------+-------------+-------------+----------------------
+--------------+
+--------+-----------+----------+---------------------+---------------------+
+--------+-----------+----------+---------------------+---------------------+
+--------+-----------+----------+---------------------+---------------------+