How can we insert data through triggers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muzammilahmedkhan
    New Member
    • Feb 2007
    • 2

    How can we insert data through triggers

    we have two tables table1 have three cols named (itemid int,itemname text,qty int)
    and contain data (1,'pepsi',100)

    and we have another table "table2" which have three cols named (orderid int,itemid int,qty int)

    i want to create trigger(inserte d) on table2 and when i insert values in table 2 i.e orderid , itemid and qty now suppose i insert qty 2
    then the table1 quantity automatically become 98 through trigger.
    please help me.



    regards
    Muzammil.A.Khan
  • Saikiran
    New Member
    • Mar 2007
    • 1

    #2
    Originally posted by muzammilahmedkh an
    we have two tables table1 have three cols named (itemid int,itemname text,qty int)
    and contain data (1,'pepsi',100)

    and we have another table "table2" which have three cols named (orderid int,itemid int,qty int)

    i want to create trigger(inserte d) on table2 and when i insert values in table 2 i.e orderid , itemid and qty now suppose i insert qty 2
    then the table1 quantity automatically become 98 through trigger.
    please help me.



    regards
    Muzammil.A.Khan
    Solution for the above Query

    create table tab1(itemid int,itemname varchar(20) null,qty int)
    create table tab2(orderid int,itemid int null,qty int)
    ----insert into tab1 values(1,'pepsi ',100)

    create trigger tr_pepsi_sai
    on tab2
    for insert
    as
    begin
    update a set a.qty=a.qty-b.qty
    from tab1 a,tab2 b
    end


    select * from tab1

    insert into tab2 values(1,1,2)

    select * from tab2

    By
    Saikiran.Akella

    Comment

    Working...