Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Practical 9

Consider the following relational schema that manages the telephone bills of a mobile phone company.

Customer (ssn, name, surname, phonenum, plan)

Pricingplan (code, connectionfee, pricepersecond)

Phonecall (ssn, date, time, callednum, seconds)

Bill (ssn, Month, Year, amount)

1. Write a trigger that after each phone call updates the customer's bill.
MariaDB [cba18162101026]> CREATE TRIGGER `upbill` AFTER INSERT ON `phonecall` FOR EACH ROW
update bill set amount = amount + new.seconds * 2;
MariaDB [cba18162101026]> show triggers in ddcba4;

MariaDB [cba18162101026]>insert into phonecall values(‘id1’,’2019-10-8’,’12:30’,’1234567890,60’);


MariaDB [cba18162101026]>select *from phonecall;

Select * from bill;

Create table GRADES with 5 columns:

SNo Number (Student's Enrollment Number)


M1 Number (Mark from test 1)

M2 Number (Mark from test 2)

M3 Number (Mark from test 3)

Avg_M Number (average mark from test 1, 2 and 3)

2. Create a trigger GRADES_TRG that calculates the value of the Avg_M column.

MariaDB [cba18162101026]>CREATE TRIGGER `Grades_trg` BEFORE INSERT ON `grades` FOR EACH ROW
set new.avg_m = (new.m1 + new.m2 + new.m3)/3;
MariaDB [cba18162101026]>insert into grades values (‘id1’,50,60,70,null);
MariaDB [cba18162101026]>select * from grades;

Create a trigger on table GRADES such that it restricts the entry of Duplicate SNo.

3. Create trigger res before insert on grades for each row


begin
declare dup int;
select count(sno) into dup from grades where sno = new.sno;
if(dup>0) then
signal sqlstate '45000' set message_text = 'duplication of ssn';
end if;
end $$

You might also like