Execute Stored Procedure when value in a field is updated

  • Hi,

    Thanks for taking time to read my post.

    I have a database with a table that keep record of stocks quantity. What I need to do is:

    When a Stock Quantity field is updated, sql server automatically executes a procedure that record the time of update and website page name from where quantity was updated.

    Please advice.

    Thanks!

  • That's called a "trigger". Look at "create trigger" on MSDN or in Books Online. They're pretty easy, if you know how to write stored procedures.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • That said, executing a procedure inside a trigger is often a sign of a poorly written trigger. What's usually better is to write the logic directly in the trigger so that you have access to the inserted and deleted tables.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply