EXPERIMENT-9 PROBLEM STATEMENT Create the Product table with the following details Name Product id Product name

Price Stock Datatype INT Varchar Number Integer Constraints Primary key -

Create the Order table with the following details Name Product id Product name Quantity Datatype INT Varchar INT Constraints References product table -

SQL> create table product(pid int primary key,pname varchar(10),price number(10),stock integer); Table created. SQL> insert into product values(1,'Soap',5,15); 1 row created. SQL> insert intSo product values(2,'Book',20,16); 1 row created. SQL> insert into product values(3,'Pencil',3,18); 1 row created. SQL> create table orders(pid int,pname varchar(10),quan int); Table created. SQL> alter table orders add constraint c1 foreign key(pid) references product(pid); Table altered. 1)Whenever a new product is inserted to the product table if the price is below Rs.50 then place an order for that product in the order table.Create a trigger to perform this task. SQL> create or replace trigger tr2 after insert on product for each row when(new.price<50) 2 begin 3 insert into orders values(:new.pid,:new.pname,:new.stock);

6)Get the information on trigger.20). 1 row created. PID PNAME QUAN ---------. SQL> alter trigger tr2 enable.---------.'mirror'. 1 row created. Trigger altered.17). SQL> select * from orders.action_type from user_triggers. 5 / Trigger created. Trigger altered.18).14.trigger_body.'scale'. 3)Disable the trigger. 4)Display the values in the order table.trigger_type.4 end tr2.---------------TRIGGER_BODY .15. TRIGGER_NAME TRIGGER_TYPE 20 17 18 -----------------------------. SQL> alter trigger tr2 disable. 1 row created.status. SQL> insert into product values(5.10.'ribbon'. SQL> insert into product values(4. SQL> select trigger_name.---------4 mirror 5 scale 6 ribbon 5)Enable the trigger. SQL> insert into product values(6. 2)Insert any three records to the product table.

----------DEF$_PROPAGATOR_TRIG DECLARE prop_count NUMBER. ENABLED PL/SQL TRIGGER_NAME TRIGGER_TYPE AFTER STATEMENT -----------------------------.---------------TRIGGER_BODY -------------------------------------------------------------------------------STATUS ACTION_TYPE -------.---------------TRIGGER_BODY -------------------------------------------------------------------------------STATUS ACTION_TYPE -------.-------------------------------------------------------------------------------STATUS ACTION_TYPE -------. END. BEGIN SELECT count(*) into prop_count FROM s ENABLED PL/SQL TRIGGER_NAME TRIGGER_TYPE BEFORE STATEMENT -----------------------------.----------REPCATLOGTRIG BEGIN sys.signal('repcatlog_alert'.----------TR2 AFTER EACH ROW . '').dbms_alert.

stock<10) 2 begin 3 insert into orders values(:new. .stock).begin insert into orders values(:new.stock). Trigger dropped.pid.:new. ENABLED PL/SQL 7)Drop the trigger.:new.pid. SQL> create or replace trigger tr1 after insert on product for each row when(new. SQL> drop trigger tr2.:new. 4 end tr2. 5 / Trigger created.:new.:new.stock).pid.pname. 9)Create the trigger to monitor the changes performed with the product table when stock=50. 8)Create a trigger to place the order for the product when the stock of the product falls below 10. SQL> create or replace trigger tr2 after updation on product for each row 2 begin 3 insert into product1 values(:new.pname.:new. 5 / Trigger created.pname. end tr2. 4 end tr1.