Can somebody explain difference between “before” and “after” trigger in oracle 10g with an example ?
Can somebody explain difference between before and after trigger in oracle 10g with an
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First, I’ll start my answer by defining trigger: a trigger is an stored procedure that is run when a row is added, modified or deleted.
Triggers can run BEFORE the action is taken or AFTER the action is taken.
BEFOREtriggers are usually used when validation needs to take place before accepting the change. They run before any change is made to the database. Let’s say you run a database for a bank. You have a tableaccountsand a tabletransactions. If a user makes a withdrawal from his account, you would want to make sure that the user has enough credits in his account for his withdrawal. TheBEFOREtrigger will allow to do that and prevent the row from being inserted intransactionsif the balance inaccountsis not enough.AFTERtriggers are usually used when information needs to be updated in a separate table due to a change. They run after changes have been made to the database (not necessarily committed). Let’s go back to our back example. After a successful transaction, you would wantbalanceto be updated in theaccountstable. AnAFTERtrigger will allow you to do exactly that.