Results 1 to 7 of 7

Thread: trigger

  1. #1
    Join Date
    Aug 2010
    Posts
    21

    Unanswered: trigger

    Hi every one.
    i created this trigger

    create trigger dec_num
    after insert on sales
    For each row mode db2sql
    update product set pro_qty = pro_qty - 1
    where EXISTS (select product.pro_id from sales,product where product.pro_id = sales.pro_id);

    insert into sales values ('s1',1.34,'2010-8-1','m1','p1h1','h1');

    after insert data into sales table all pro_qty form product table decrement by 1

  2. #2
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    Please supply DDLs of product and sales and sample data of product.

  3. #3
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    You posted recently another two questions, right?

    I guessed that all three questions are related to an requirement.

    If so, please describe your concrete requirements without using SQL statements like "UPDATE product ..." / "CREATE trigger ...".

  4. #4
    Join Date
    Aug 2010
    Posts
    21
    Hi . i have to table sales and product . table product has field pro_id and pro_name and pro_qty ,and table sales has sal_id and pro_id(foreign key) . i want pro_qty in table product decrement by one when one item insert into table sales.

  5. #5
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    if I buy 2 or more of an item, do you put 2 or more rows into sales? or do you have a quantity filed?

  6. #6
    Join Date
    Aug 2010
    Posts
    21
    yes. put 2 or more rows into sales

  7. #7
    Join Date
    Aug 2010
    Posts
    21
    quantity filed exists in table product

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •