INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

auto execute procedure/query on record insert

auto execute procedure/query on record insert

(OP)
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

RE: auto execute procedure/query on record insert

You should probably start by looking at triggers.

RE: auto execute procedure/query on record insert

(OP)
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.

RE: auto execute procedure/query on record insert

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

RE: auto execute procedure/query on record insert

(OP)
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?

RE: auto execute procedure/query on record insert

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.

RE: auto execute procedure/query on record insert

Quote (rk68)

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.

RE: auto execute procedure/query on record insert

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

RE: auto execute procedure/query on record insert

(OP)
i need to do the calculation for the new row insert.

RE: auto execute procedure/query on record insert

(OP)
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

RE: auto execute procedure/query on record insert

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

RE: auto execute procedure/query on record insert

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.

RE: auto execute procedure/query on record insert

(OP)
Ok, will try it out. Thankyou.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close