SQL Server triggers - order of execution

前端 未结 10 1205
旧时难觅i
旧时难觅i 2020-12-16 09:39

Does anyone know how SQL Server determines the order triggers (of same type, i.e. before triggers) are executed. And is there any way of changing this so that I can specify

10条回答
  •  长情又很酷
    2020-12-16 10:28

    Use sp_Settriggerorder stored procedure, you can define the execution order of the trigger.

    sp_settriggerorder [ @triggername = ] ‘[ triggerschema. ] triggername’
    , [ @order = ] ‘value’
    , [ @stmttype = ] ’statement_type’
    [ , [ @namespace = ] { ‘DATABASE’ | ‘SERVER’ | NULL } ]
    

    The second parameter, “order” can take three values which means that it can take into account up-to three triggers.

    1. First – Trigger is fired first
    2. Last - Trigger is fired last
    3. None – Trigger is fired in random order.

提交回复
热议问题