If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > trigger

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-20-10, 09:38
calamaris calamaris is offline
Registered User
 
Join Date: Aug 2010
Posts: 21
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
Reply With Quote
  #2 (permalink)  
Old 08-20-10, 13:42
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Please supply DDLs of product and sales and sample data of product.
Reply With Quote
  #3 (permalink)  
Old 08-20-10, 14:00
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
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 ...".
Reply With Quote
  #4 (permalink)  
Old 08-26-10, 12:52
calamaris calamaris is offline
Registered User
 
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.
Reply With Quote
  #5 (permalink)  
Old 08-26-10, 13:02
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
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?
Reply With Quote
  #6 (permalink)  
Old 08-26-10, 13:16
calamaris calamaris is offline
Registered User
 
Join Date: Aug 2010
Posts: 21
yes. put 2 or more rows into sales
Reply With Quote
  #7 (permalink)  
Old 08-26-10, 13:18
calamaris calamaris is offline
Registered User
 
Join Date: Aug 2010
Posts: 21
quantity filed exists in table product
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On