Results 1 to 4 of 4
  1. #1
    Join Date
    May 2009

    Question Unanswered: ask:procedure and trigger

    can you give me some examples of using procedure and trigger plz?i amnot so understand using procedure and trigger.when i see the tutorial in msdn,i am so confuse..

  2. #2
    Join Date
    May 2009
    Provided Answers: 1
    compileman. Triggers are objects you create that 'fire' (activate) when a row on a table that it was create for is changed (Insert, Update, Delete). It could be for any column or specific column(s). For example:

    Table with columns, Price, Discount, Discount Price.

    If a trigger is created for Update of Discount, when Discount is Updated, you could have it update Discount Price with Price * Discount.
    (This may not be a realistic example as you probably would save a value you could calculate in the table).


    Create Insert, Update and Create triggers so that if any column changes, you can Insert the row Before and/or After the change along with the User, and Timestamp to create an Audit table that tracks changes.

    As for Stored Procedures, they are basically Programs. As such they can do just about anything you like.

  3. #3
    Join Date
    Jun 2003
    Provided Answers: 1
    Procedures are part of your database's Somatic nervous system. They fire only when specifically requested.
    Triggers are part or your database's Autonomic nervous system. They operate in the background all the time, without concious control.
    If it's not practically useful, then it's practically useless.

    blindman "sqlblindman"

  4. #4
    Join Date
    Jul 2006
    You can view a trigger the similar way as a s.p. (both are piece of code stored in the database) except that trigger will be executed in an AUTOMATIC fashion while s.p. need to be executed EXPLICITLY.

    If you want some code to be executed automatically when there is an event (insert, update or delete) in a table then use a trigger on that table.

    For a s.p. to run it needs the "execute ProcedureName <+ parameters>" command.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts