difference before and after trigger in oracle

后端 未结 3 1813
半阙折子戏
半阙折子戏 2020-12-09 04:55

Can somebody explain difference between \"before\" and \"after\" trigger in oracle 10g with an example ?

3条回答
  •  死守一世寂寞
    2020-12-09 05:09

    I'm not completely sure what you're interested in knowing, so I'll keep this fundamental.

    Before Triggers

    • As per the name, these triggers are fired prior to creating the row in the table. Subsequently, since the row has not yet been created you have full access to the :new.table_element field. This allows for data cleansing and uniformity if unwanted/malformed data is attempting to be inserted/updated. This is just a basic example, but you need to utilize the before trigger any time you may require access to the ":new" data.

    After Triggers

    • Since the after trigger fires once the row has already been created, these triggers are typically utilized when you want logic to occur due to the row. For example, if you have an address table and a user updates his/her address, then you may want to update the address reference ids in an xref table upon creation (if you happen to be retaining all old addresses as well). Also, unlike the before trigger, you do not have access to modify any of the column values since the row already exists in the table.

提交回复
热议问题