0% found this document useful (0 votes)
5 views5 pages

Trigger

FYBBACA

Uploaded by

Amruta Navale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Trigger

FYBBACA

Uploaded by

Amruta Navale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Assignment No.

6: Triggers
SET A :

Consider the following entities and their relationships.

Employee (emp_id, emp_name, address)


Investment (inv_no, inv_name, inv_date, inv_amount)
Relation between Employee and Investment is One to Many.

Constraint: Primary key, inv_amount should be > 0.

Create a RDB in 3NF and write PL/SQL blocks in Oracle for the
following:
1) Write a trigger which will fire before insert or update on Employee having
Emp id less than equal to zero (Raise user defined exception and give
appropriate message)

create or replace trigger t5 before insert or update on employee for each row
begin
if(:new.emp_id<=0) then
raise_application_error(-20003,'ERROR::Emp id should be greater than
zero');
end if;
end;

2..Write a trigger which will fire before insert or update on Investment having
investment amount less than 10000. (Raise user defined exception and give
appropriate message)

create or replace trigger t6 before insert or update on inv for each row

begin

if(:new.i_amt<10000) then
raise_application_error(-20001,'ERROR::Investment amt should be greater than
50000');

end if;

end;
Slip Questions:

1.Write a trigger which will fire before insert or update on book having price less
than or equal to zero. (Raise user defined exception and give appropriate message)

create or replace trigger t5 before insert or update on book for each row

begin

if(:new.price<=0) then

raise_application_error(-20003,'ERROR::Price should be greater than zero');

end if;

end;

2.Write a trigger which will fire before insert or update on mobile number having
length less than or greater than10. (Raise user defined exception and give
appropriate message)

create or replace trigger t8 before insert or update on cust for each row

begin

if(length(:new.mobile_no)<10 or length(:new.mobile_no)>10) then

raise_application_error(-20004,'ERROR::Mobile no should be 10 digits');

end if;

end;
3. Write a trigger which will fire before insert or update on project having budget
less than or equal to zero. (Raise user defined exception and give appropriate
message)

create or replace trigger t9 before insert or update on project1 for each row

begin

If(:new.budget<=0) then

raise_application_error(-20001,'ERROR::Budget should be greater than zero');

end if;

end;

SET B

1. Write a trigger which will fire before insert or update on Gym having charges
less than 1000. (Raise user defined exception and give appropriate message)

create or replace trigger t11 before insert or update on gym1 for each row

begin

if(:new.charges<1000) then

raise_application_error(-20002,'ERROR::Charges should be greater than 1000');

end if;

end;

6.Write a trigger which will fire before delete on Lab (Raise user defined exception
and give appropriate message)

create or replace trigger t12 before delete on lab4 for each row

declare

del_lab exception;
begin

raise del_lab;

exception

when del_lab then

raise_application_error(-20001,'ERROR::Record can not be deleted');

You might also like