Trigger & Stored Procedure Question

  • Should all updates be configured inside my Trigger or can I set the Trigger to fire off a Stored Proc that does all the processing? 

    For instance, my Trigger now contains the UPDATE TABLE/INSERT INTO commands.  I would like to replicate this within a Stored Proc and have the Trigger call them:  EXEC sp_Update/Insert @variable1, @variable2. 

    Thanks!

     

  • Why don't you just try it?

    It would probably take less time than writing the post.

    Of course you can do it.

    Just don't use cursors inside of triggers.

    _____________
    Code for TallyGenerator

  • I actually have already tested it, but not against production.  I generally feel more comfortable knowing I'm not doing something out of the ordinary or that's not recommended. 

    Thanks a bunch!

  • Don't forget, inserted & deleted tables are not available inside the stored proc.

    If the @parameters you're passing into the stored proc are somehow derived from a query on the inserted/deleted trigger tables, you will have designed something that doesn't support multi-row inserts/updates/deletes.

     

  • I use to copy data from inserted to #inserted and from deleted to #deleted.

    And if some nvarchar fields in table inserted must be trimmed I do it in this copy script.

    These #tables can be used as "multi-row" parameters.

    _____________
    Code for TallyGenerator

Viewing 5 posts - 1 through 4 (of 4 total)

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