Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.