doubt about triggers

  • If i put a trigger which executes before some data is inserted/udpated into a table.

    and if that trigger calls a function, which raises exception, will the insertion of data into the table will be succesfull or not ?

  • That depends on what kind of error it is and whther you use TRY..CATCH.. to trap it or not.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • I am wondering how you can write a trigger that would be fired before inserting/updating rows into a table.

    If i am not wrong a trigger will fire either after or instead of the event that actually fired the trigger.

    Regards,

    Sam.

  • Can u provide the trigger script and sample data from the table associated with that trigger...after that anyopne can porvide you better help 🙂

    -------Bhuvnesh----------
    I work only to learn Sql Server...though my company pays me for getting their stuff done;-)

  • If you want "before" you must use "instead" and then perform the functions you want to do before the update/delete/insert is performed and then perform the update/delete/insert in code. That's how I understand it.

  • samsqlserver (12/22/2008)


    I am wondering how you can write a trigger that would be fired before inserting/updating rows into a table.

    If i am not wrong a trigger will fire either after or instead of the event that actually fired the trigger.

    Yes, you are correct Sam. The OP would have to use an INSTEAD OF trigger and then do the actual insert/update themselves.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • Yes, you are correct Sam.

    The OP would have to use an INSTEAD OF trigger and then do the actual insert/update themselves.

    Thankyou. I just realized it.

    It's all about improvising and using the same thing it in different ways.

    Regards,

    Sam.

Viewing 7 posts - 1 through 6 (of 6 total)

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