Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

auto execute procedure/query on record insert

Status
Not open for further replies.

rk68

Programmer
Jul 15, 2003
171
IN
Hi,

I have to do some calculations & update couple of fields in a table on record insert.
This calculations can executed thru a procedure or SQL but has to happen automatically on each insert.

How can this be done?

TIA,
Raj
 
You should probably start by looking at triggers.
 
Which trigger would work?
Its a billing system. So when the invoice details is inserted in the table, I have to calculate the loyalty points earned on that invoice.
 
If the loyalty points are in the invoice record then use a BEFORE INSERT trigger on the invoice table. If it is stored in a different table, I would use an AFTER INSERT trigger.

Bill
Lead Application Developer
New York State, USA
 
Invoice amount will be inserted in the invoice table. On insert I need to calculate the loyalty point on the invoice amt and update the points in the invoice table.
Will using BEFORE INSERT trigger will help?
 
Your best bet would be to try it and see.
As my mentor used to tell me, "An ounce of experimentation is worth a pound of expert opinion."
You have two people telling you to try a Before Insert trigger. At this point you might as well try a Before Insert trigger.
 
rk68 said:
I need to calculate the loyalty point on the invoice amt and update the points in the invoice table.
My question would be: Do I want to do all the calculations / updates BEFORE the insert so I deal with the existing / old data?
Or do I want to do all of that with the NEW data AFTER the Insert is done?

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
You can't modify a new row unless you are using a before insert trigger. You reference the new data in the row using the code

:new.my_column


Bill
Lead Application Developer
New York State, USA
 
i need to do the calculation for the new row insert.
 
BEFORE INSERT trigger worked. Thanks
But wanted to know will it affect the performance when there is bulk insert happening & trigger is fired of each insert.
Is there some limitation. I want to use this for POS system where there would be billing happening through out the day, so is it gonna affect my system...what precautions need to taken

TIA
Raj
 
Unless the calculation for the loyalty points is an intense computation the effect will be very small.

Bill
Lead Application Developer
New York State, USA
 
Again, the only way to really find out is to try it.
Once your trigger is working, you can take measurements with the trigger enabled and disabled to determine what the difference is.
As Bill points out, a lot will depend on how complicated your computation is.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top