Assignment in SQL for Using trigger


Assignment:-               
Assign. Name:-Using Trigger
CLASS:-T.Y.B.Sc(Computer)     



     *************************************************************

Triggers:-

 SQL> select * from purchase

 PO_NO   PO_DATE     ITEM_NO    QTY
 --------  ---------            ----------    ---------
 11          12-MAY-03      101        100
 12          17-JUN-03       102        75
 13          21-APR-03       103        150
 14          14-JAN-04       104        100

 SQL> select * from stock;

 ITEM_NO       QTY
-----------  -----------
  101            100
  102             75
  103            150
  104            100

      <1>                       

     create or replace trigger ptr1 before insert on purchase for each row
     declare
     v1 integer;
     begin
    select count(*) into v1 from stock
    where Itrmno=:new.Item_no;
    if v1=0 then
    insert into stock values(:new.Itemno,:new.qty)
    else
    update stock set qty=qty+:new.qty
    where Itemno=:new.Itemno;
    end if;
    end;
    /
SQL> select * from purchase;

Comments

Popular posts from this blog

Solve

Solved practical slips of 12th Computer Science journal

SOLVE QUESTION ANSWERS ON OPERATING SYSTEM .