Jump to content

simple trigger


ballouta

Recommended Posts

Hello

I have two tables:

1) order_line (order_number, part_number,number_oredred, quoted_price)

2) part (part_number, units_on_hands, item_class...)

 

i am requested to write an INSERT trigger on order_line table. the trigger should decrease the units on hands in the part table for the part just inserted into the order_line table.

 

I am trying to write this trigger by myself, but I have something wrong. Please Help

 

delimiter //
create trigger order_line_ai
After Insert
on order_line
for each row
Begin
Set @part_num = New.part_number;
update part set units_on_hands = units_on_hands-- where part.part_number = @part_num;
End;
//

Link to comment
https://forums.phpfreaks.com/topic/234638-simple-trigger/
Share on other sites

hi, I have just tested this trigger in my workbench, It dosent like the -- you are using to decrease the number by one. Try

delimiter //
create trigger order_line_ai
After Insert
on order_line
for each row
Begin
Set @part_num = New.part_number;
update part set units_on_hands = units_on_hands - 1 where part.part_number = @part_num;
End;
//

Link to comment
https://forums.phpfreaks.com/topic/234638-simple-trigger/#findComment-1205788
Share on other sites

Thank you so much

it is working

 

Kindly i have a question

is there anyway to put the insert statement inside this trigger?

I am confused because the examples in saw in the book make some kind of filtration on the insert command,

but in this question, we are not doing any kind of filtration except we r decreasing an amount from another table. correct?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/234638-simple-trigger/#findComment-1205789
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.